From 34b9fa508ad0f2255d7b006fca3d299e3a45f151 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Wed, 2 Jul 2014 17:44:20 +0100 Subject: [PATCH 01/22] Add first set of unit tests using Robolectric --- library/build.gradle | 13 +++ .../ClassAnnotationParserTest.java | 57 +++++++++ .../easyadapter/EasyAdapterUtilTest.java | 109 ++++++++++++++++++ .../FieldAnnotationParserTest.java | 59 ++++++++++ 4 files changed, 238 insertions(+) create mode 100644 library/src/androidTest/java/uk/co/ribot/easyadapter/ClassAnnotationParserTest.java create mode 100644 library/src/androidTest/java/uk/co/ribot/easyadapter/EasyAdapterUtilTest.java create mode 100644 library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java diff --git a/library/build.gradle b/library/build.gradle index 0174e78..f251cf0 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,14 +1,27 @@ import com.android.builder.core.BuilderConstants +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+' + } +} + apply plugin: 'com.android.library' apply plugin: 'maven' apply plugin: 'signing' +apply plugin: 'android-test' version = "1.1.0" group = "uk.co.ribot" dependencies { compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) + + androidTestCompile 'junit:junit:4.11' + androidTestCompile 'org.robolectric:robolectric:2.3' } android { diff --git a/library/src/androidTest/java/uk/co/ribot/easyadapter/ClassAnnotationParserTest.java b/library/src/androidTest/java/uk/co/ribot/easyadapter/ClassAnnotationParserTest.java new file mode 100644 index 0000000..db1c9c6 --- /dev/null +++ b/library/src/androidTest/java/uk/co/ribot/easyadapter/ClassAnnotationParserTest.java @@ -0,0 +1,57 @@ +package uk.co.ribot.easyadapter; + +import android.view.View; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import uk.co.ribot.easyadapter.annotations.ClassAnnotationParser; +import uk.co.ribot.easyadapter.annotations.LayoutId; + +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public class ClassAnnotationParserTest { + + private static final int LAYOUT_ID = 1; + + @Test public void testGetLayoutId() throws Exception{ + Integer layoutId = ClassAnnotationParser.getLayoutId(ItemViewHolderWithLayoutId.class); + Assert.assertTrue(layoutId.equals(LAYOUT_ID)); + } + + @Test public void testGetLayoutIdWithoutAnnotation() throws Exception{ + Integer layoutId = ClassAnnotationParser.getLayoutId(ItemViewHolderWithoutLayoutId.class); + Assert.assertNull(layoutId); + } + + /*** Test ItemViewHolders ***/ + + @LayoutId(LAYOUT_ID) + private static class ItemViewHolderWithLayoutId extends ItemViewHolder { + + ItemViewHolderWithLayoutId(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + } + + private static class ItemViewHolderWithoutLayoutId extends ItemViewHolder { + + ItemViewHolderWithoutLayoutId(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + } +} diff --git a/library/src/androidTest/java/uk/co/ribot/easyadapter/EasyAdapterUtilTest.java b/library/src/androidTest/java/uk/co/ribot/easyadapter/EasyAdapterUtilTest.java new file mode 100644 index 0000000..8c46957 --- /dev/null +++ b/library/src/androidTest/java/uk/co/ribot/easyadapter/EasyAdapterUtilTest.java @@ -0,0 +1,109 @@ +package uk.co.ribot.easyadapter; + +import android.view.View; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import uk.co.ribot.easyadapter.annotations.LayoutId; + + +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public class EasyAdapterUtilTest { + + private static final int LAYOUT_ID = 1; + + @Test public void testCreateViewHolder() throws Exception { + View view = new View(Robolectric.application); + ItemViewHolder itemViewHolder = EasyAdapterUtil.createViewHolder(view, ValidItemViewHolder.class); + Assert.assertNotNull(itemViewHolder); + } + + @Test public void testCreateInvalidViewHolder() throws Exception { + View view = new View(Robolectric.application); + InvalidViewHolderException exception = null; + try { + //Should throw a InvalidViewHolderException exception + EasyAdapterUtil.createViewHolder(view, InvalidItemViewHolder.class); + }catch (InvalidViewHolderException e) { + exception = e; + } + Assert.assertNotNull(exception); + } + + @Test public void testParseItemLayoutId() throws Exception { + Integer layoutId = EasyAdapterUtil.parseItemLayoutId(ItemViewHolderWithLayoutId.class); + Assert.assertTrue(layoutId.equals(LAYOUT_ID)); + } + + @Test public void testParseItemLayoutIdWithoutLayoutId() throws Exception { + LayoutIdMissingException exception = null; + try { + EasyAdapterUtil.parseItemLayoutId(ItemViewHolderWithoutLayoutId.class); + }catch (LayoutIdMissingException e) { + exception = e; + } + Assert.assertNotNull(exception); + } + + /*** Test ItemViewHolders ***/ + + private static class ValidItemViewHolder extends ItemViewHolder { + + public ValidItemViewHolder(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + + } + + //This ItemViewHolder is invalid because it has another parameter in the constructor + private static class InvalidItemViewHolder extends ItemViewHolder { + + public InvalidItemViewHolder(View view, int anotherParam) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + + } + + @LayoutId(LAYOUT_ID) + private static class ItemViewHolderWithLayoutId extends ItemViewHolder { + + ItemViewHolderWithLayoutId(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + } + + //This view holders doesn't have a LayoutId annotation + private static class ItemViewHolderWithoutLayoutId extends ItemViewHolder { + + ItemViewHolderWithoutLayoutId(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + } +} diff --git a/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java b/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java new file mode 100644 index 0000000..2c0fc14 --- /dev/null +++ b/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java @@ -0,0 +1,59 @@ +package uk.co.ribot.easyadapter; + +import android.annotation.TargetApi; +import android.os.Build; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import uk.co.ribot.easyadapter.annotations.FieldAnnotationParser; +import uk.co.ribot.easyadapter.annotations.ViewId; + +@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) //Disable because this code will run inside robolectric with api level 17+ +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public class FieldAnnotationParserTest { + + private static final int TEXT_VIEW_ID = 1000; + private static final int IMAGE_VIEW_ID = 2000; + + @Test public void testSetViewFields() throws Exception { + TestObjectWithAnnotations testObject = new TestObjectWithAnnotations(); + FieldAnnotationParser.setViewFields(testObject, createTestLinearLayout()); + Assert.assertNotNull(testObject.textView); + Assert.assertNotNull(testObject.imageView); + } + +/* @Test public void testSetViewFieldsActivity() throws Exception { + + }*/ + + @SuppressWarnings("ResourceType") //Because of warning when setting a hardcoded ID into the view + private LinearLayout createTestLinearLayout() { + LinearLayout linearLayout = new LinearLayout(Robolectric.application); + TextView textView = new TextView(Robolectric.application); + textView.setId(TEXT_VIEW_ID); + linearLayout.addView(textView); + ImageView imageView = new ImageView(Robolectric.application); + imageView.setId(IMAGE_VIEW_ID); + linearLayout.addView(imageView); + return linearLayout; + } + + private class TestObjectWithAnnotations { + + @ViewId(TEXT_VIEW_ID) + TextView textView; + @ViewId(IMAGE_VIEW_ID) + ImageView imageView; + + } +} From d0117ee26993e590aba3a607a178c78efd5f2878 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:04:51 +0100 Subject: [PATCH 02/22] Add test testSetViewFieldsActivity --- .../FieldAnnotationParserTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java b/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java index 2c0fc14..9badcd8 100644 --- a/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java +++ b/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java @@ -1,7 +1,9 @@ package uk.co.ribot.easyadapter; import android.annotation.TargetApi; +import android.app.Activity; import android.os.Build; +import android.os.Bundle; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -32,12 +34,16 @@ public class FieldAnnotationParserTest { Assert.assertNotNull(testObject.imageView); } -/* @Test public void testSetViewFieldsActivity() throws Exception { - - }*/ + @Test public void testSetViewFieldsActivity() throws Exception { + Activity testActivity = Robolectric.buildActivity(TestActivity.class).create().get(); + TestObjectWithAnnotations testObject = new TestObjectWithAnnotations();; + FieldAnnotationParser.setViewFields(testObject, testActivity); + Assert.assertNotNull(testObject.textView); + Assert.assertNotNull(testObject.imageView); + } @SuppressWarnings("ResourceType") //Because of warning when setting a hardcoded ID into the view - private LinearLayout createTestLinearLayout() { + private static LinearLayout createTestLinearLayout() { LinearLayout linearLayout = new LinearLayout(Robolectric.application); TextView textView = new TextView(Robolectric.application); textView.setId(TEXT_VIEW_ID); @@ -56,4 +62,12 @@ private class TestObjectWithAnnotations { ImageView imageView; } + + static class TestActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(createTestLinearLayout()); + } + } } From 1cfeb970e5e78c5fc1e87891a6907e426e75667e Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:27:47 +0100 Subject: [PATCH 03/22] Update travis config with google repository --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6196cfd..43332a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: # Install base Android SDK - sudo apt-get update -qq - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support + - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-google-m2repository - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - source ~/.android-sdk-installer/env From c56403d28529e4fa9d79bc40f7b7a215bd112042 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:33:49 +0100 Subject: [PATCH 04/22] Update travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 43332a8..8c62a8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: # Install base Android SDK - sudo apt-get update -qq - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-google-m2repository + - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-google-m2repository - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - source ~/.android-sdk-installer/env From 58b995be31bc4a28ad1432656d015ed966aeaff6 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:43:18 +0100 Subject: [PATCH 05/22] Update travis config, add module extra-android-m2repository --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8c62a8e..0cce2dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: # Install base Android SDK - sudo apt-get update -qq - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-google-m2repository + - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-android-m2repository - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - source ~/.android-sdk-installer/env From 8d691212723a297622b16e0c45075fb776993662 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:51:33 +0100 Subject: [PATCH 06/22] Update travis config using extra-google-m2repository --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0cce2dc..8c62a8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: # Install base Android SDK - sudo apt-get update -qq - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-android-m2repository + - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-google-m2repository - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - source ~/.android-sdk-installer/env From 3cedea62ac88413e20f857be467d35f956dcc08c Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Wed, 2 Jul 2014 17:44:20 +0100 Subject: [PATCH 07/22] Add first set of unit tests using Robolectric --- library/build.gradle | 13 +++ .../ClassAnnotationParserTest.java | 57 +++++++++ .../easyadapter/EasyAdapterUtilTest.java | 109 ++++++++++++++++++ .../FieldAnnotationParserTest.java | 59 ++++++++++ 4 files changed, 238 insertions(+) create mode 100644 library/src/androidTest/java/uk/co/ribot/easyadapter/ClassAnnotationParserTest.java create mode 100644 library/src/androidTest/java/uk/co/ribot/easyadapter/EasyAdapterUtilTest.java create mode 100644 library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java diff --git a/library/build.gradle b/library/build.gradle index fe05f09..397510c 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,14 +1,27 @@ import com.android.builder.core.BuilderConstants +buildscript { + repositories { + mavenCentral() + } + dependencies { + classpath 'org.robolectric.gradle:gradle-android-test-plugin:0.10.+' + } +} + apply plugin: 'com.android.library' apply plugin: 'maven' apply plugin: 'signing' +apply plugin: 'android-test' version = "1.1.0" group = "uk.co.ribot" dependencies { compile fileTree(dir: 'libs', include: ['*.jar', '*.aar']) + + androidTestCompile 'junit:junit:4.11' + androidTestCompile 'org.robolectric:robolectric:2.3' } android { diff --git a/library/src/androidTest/java/uk/co/ribot/easyadapter/ClassAnnotationParserTest.java b/library/src/androidTest/java/uk/co/ribot/easyadapter/ClassAnnotationParserTest.java new file mode 100644 index 0000000..db1c9c6 --- /dev/null +++ b/library/src/androidTest/java/uk/co/ribot/easyadapter/ClassAnnotationParserTest.java @@ -0,0 +1,57 @@ +package uk.co.ribot.easyadapter; + +import android.view.View; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import uk.co.ribot.easyadapter.annotations.ClassAnnotationParser; +import uk.co.ribot.easyadapter.annotations.LayoutId; + +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public class ClassAnnotationParserTest { + + private static final int LAYOUT_ID = 1; + + @Test public void testGetLayoutId() throws Exception{ + Integer layoutId = ClassAnnotationParser.getLayoutId(ItemViewHolderWithLayoutId.class); + Assert.assertTrue(layoutId.equals(LAYOUT_ID)); + } + + @Test public void testGetLayoutIdWithoutAnnotation() throws Exception{ + Integer layoutId = ClassAnnotationParser.getLayoutId(ItemViewHolderWithoutLayoutId.class); + Assert.assertNull(layoutId); + } + + /*** Test ItemViewHolders ***/ + + @LayoutId(LAYOUT_ID) + private static class ItemViewHolderWithLayoutId extends ItemViewHolder { + + ItemViewHolderWithLayoutId(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + } + + private static class ItemViewHolderWithoutLayoutId extends ItemViewHolder { + + ItemViewHolderWithoutLayoutId(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + } +} diff --git a/library/src/androidTest/java/uk/co/ribot/easyadapter/EasyAdapterUtilTest.java b/library/src/androidTest/java/uk/co/ribot/easyadapter/EasyAdapterUtilTest.java new file mode 100644 index 0000000..8c46957 --- /dev/null +++ b/library/src/androidTest/java/uk/co/ribot/easyadapter/EasyAdapterUtilTest.java @@ -0,0 +1,109 @@ +package uk.co.ribot.easyadapter; + +import android.view.View; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import uk.co.ribot.easyadapter.annotations.LayoutId; + + +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public class EasyAdapterUtilTest { + + private static final int LAYOUT_ID = 1; + + @Test public void testCreateViewHolder() throws Exception { + View view = new View(Robolectric.application); + ItemViewHolder itemViewHolder = EasyAdapterUtil.createViewHolder(view, ValidItemViewHolder.class); + Assert.assertNotNull(itemViewHolder); + } + + @Test public void testCreateInvalidViewHolder() throws Exception { + View view = new View(Robolectric.application); + InvalidViewHolderException exception = null; + try { + //Should throw a InvalidViewHolderException exception + EasyAdapterUtil.createViewHolder(view, InvalidItemViewHolder.class); + }catch (InvalidViewHolderException e) { + exception = e; + } + Assert.assertNotNull(exception); + } + + @Test public void testParseItemLayoutId() throws Exception { + Integer layoutId = EasyAdapterUtil.parseItemLayoutId(ItemViewHolderWithLayoutId.class); + Assert.assertTrue(layoutId.equals(LAYOUT_ID)); + } + + @Test public void testParseItemLayoutIdWithoutLayoutId() throws Exception { + LayoutIdMissingException exception = null; + try { + EasyAdapterUtil.parseItemLayoutId(ItemViewHolderWithoutLayoutId.class); + }catch (LayoutIdMissingException e) { + exception = e; + } + Assert.assertNotNull(exception); + } + + /*** Test ItemViewHolders ***/ + + private static class ValidItemViewHolder extends ItemViewHolder { + + public ValidItemViewHolder(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + + } + + //This ItemViewHolder is invalid because it has another parameter in the constructor + private static class InvalidItemViewHolder extends ItemViewHolder { + + public InvalidItemViewHolder(View view, int anotherParam) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + + } + + @LayoutId(LAYOUT_ID) + private static class ItemViewHolderWithLayoutId extends ItemViewHolder { + + ItemViewHolderWithLayoutId(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + } + + //This view holders doesn't have a LayoutId annotation + private static class ItemViewHolderWithoutLayoutId extends ItemViewHolder { + + ItemViewHolderWithoutLayoutId(View view) { + super(view); + } + + @Override + public void onSetValues(Object item, PositionInfo positionInfo) { + + } + } +} diff --git a/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java b/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java new file mode 100644 index 0000000..2c0fc14 --- /dev/null +++ b/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java @@ -0,0 +1,59 @@ +package uk.co.ribot.easyadapter; + +import android.annotation.TargetApi; +import android.os.Build; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.TextView; + +import junit.framework.Assert; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; + +import uk.co.ribot.easyadapter.annotations.FieldAnnotationParser; +import uk.co.ribot.easyadapter.annotations.ViewId; + +@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) //Disable because this code will run inside robolectric with api level 17+ +@RunWith(RobolectricTestRunner.class) +@Config(manifest = Config.NONE) +public class FieldAnnotationParserTest { + + private static final int TEXT_VIEW_ID = 1000; + private static final int IMAGE_VIEW_ID = 2000; + + @Test public void testSetViewFields() throws Exception { + TestObjectWithAnnotations testObject = new TestObjectWithAnnotations(); + FieldAnnotationParser.setViewFields(testObject, createTestLinearLayout()); + Assert.assertNotNull(testObject.textView); + Assert.assertNotNull(testObject.imageView); + } + +/* @Test public void testSetViewFieldsActivity() throws Exception { + + }*/ + + @SuppressWarnings("ResourceType") //Because of warning when setting a hardcoded ID into the view + private LinearLayout createTestLinearLayout() { + LinearLayout linearLayout = new LinearLayout(Robolectric.application); + TextView textView = new TextView(Robolectric.application); + textView.setId(TEXT_VIEW_ID); + linearLayout.addView(textView); + ImageView imageView = new ImageView(Robolectric.application); + imageView.setId(IMAGE_VIEW_ID); + linearLayout.addView(imageView); + return linearLayout; + } + + private class TestObjectWithAnnotations { + + @ViewId(TEXT_VIEW_ID) + TextView textView; + @ViewId(IMAGE_VIEW_ID) + ImageView imageView; + + } +} From 06ebd1d113c511070ce87069547e88d0f2340ff7 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:04:51 +0100 Subject: [PATCH 08/22] Add test testSetViewFieldsActivity --- .../FieldAnnotationParserTest.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java b/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java index 2c0fc14..9badcd8 100644 --- a/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java +++ b/library/src/androidTest/java/uk/co/ribot/easyadapter/FieldAnnotationParserTest.java @@ -1,7 +1,9 @@ package uk.co.ribot.easyadapter; import android.annotation.TargetApi; +import android.app.Activity; import android.os.Build; +import android.os.Bundle; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -32,12 +34,16 @@ public class FieldAnnotationParserTest { Assert.assertNotNull(testObject.imageView); } -/* @Test public void testSetViewFieldsActivity() throws Exception { - - }*/ + @Test public void testSetViewFieldsActivity() throws Exception { + Activity testActivity = Robolectric.buildActivity(TestActivity.class).create().get(); + TestObjectWithAnnotations testObject = new TestObjectWithAnnotations();; + FieldAnnotationParser.setViewFields(testObject, testActivity); + Assert.assertNotNull(testObject.textView); + Assert.assertNotNull(testObject.imageView); + } @SuppressWarnings("ResourceType") //Because of warning when setting a hardcoded ID into the view - private LinearLayout createTestLinearLayout() { + private static LinearLayout createTestLinearLayout() { LinearLayout linearLayout = new LinearLayout(Robolectric.application); TextView textView = new TextView(Robolectric.application); textView.setId(TEXT_VIEW_ID); @@ -56,4 +62,12 @@ private class TestObjectWithAnnotations { ImageView imageView; } + + static class TestActivity extends Activity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(createTestLinearLayout()); + } + } } From 740c5c5bd008aece05a344b4a3eef6dc85e8d680 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:27:47 +0100 Subject: [PATCH 09/22] Update travis config with google repository --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6196cfd..43332a8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: # Install base Android SDK - sudo apt-get update -qq - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support + - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-google-m2repository - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - source ~/.android-sdk-installer/env From 54fb03a80226377e3044db90bbc3ebf6f396018f Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:33:49 +0100 Subject: [PATCH 10/22] Update travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 43332a8..8c62a8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: # Install base Android SDK - sudo apt-get update -qq - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-google-m2repository + - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-google-m2repository - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - source ~/.android-sdk-installer/env From 1d4c483bdf8e4ef2d0f0fb95a37b588884cdcdd0 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:43:18 +0100 Subject: [PATCH 11/22] Update travis config, add module extra-android-m2repository --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8c62a8e..0cce2dc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: # Install base Android SDK - sudo apt-get update -qq - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-google-m2repository + - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-android-m2repository - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - source ~/.android-sdk-installer/env From b93029981f8b04467ede7659ee1bb97e57dd8ef5 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Thu, 3 Jul 2014 11:51:33 +0100 Subject: [PATCH 12/22] Update travis config using extra-google-m2repository --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0cce2dc..8c62a8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ before_install: # Install base Android SDK - sudo apt-get update -qq - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-android-m2repository + - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-google-m2repository - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - source ~/.android-sdk-installer/env From 32c97e1897ee72c8cf25d7653575268bc02b2ad8 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Mon, 7 Jul 2014 17:24:19 +0100 Subject: [PATCH 13/22] Update travis config to use new android language --- .travis.yml | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c62a8e..6fd7f80 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,22 @@ -language: java -jdk: oraclejdk7 -before_install: - # Install base Android SDK - - sudo apt-get update -qq - - sudo apt-get install -qq libstdc++6:i386 lib32z1 expect - - export COMPONENTS=build-tools-19.1.0,android-19,sys-img-armeabi-v7a-android-19,extra-android-support,extra-google-m2repository - - curl -L https://raw.github.com/embarkmobile/android-sdk-installer/version-2/android-sdk-installer | bash /dev/stdin --install=$COMPONENTS - - source ~/.android-sdk-installer/env +language: android +android: + components: + - build-tools-19.0.3 +before_install: # Create and start emulator - echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a - emulator -avd test -no-skin -no-audio -no-window & + # for gradle output style + - export TERM=dumb + + + # environment info + - ./gradlew -v + - uname -a + before_script: - - wait_for_emulator + - wait_for_emulator -script: ./gradlew demo:connectedCheck +script: ./gradlew clean demo:connectedCheck From dfb52efd3529fa106654f1fe4dcb4c391827f19a Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Mon, 7 Jul 2014 17:30:22 +0100 Subject: [PATCH 14/22] Update travis config --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 6fd7f80..2fa8fb4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ before_install: - uname -a before_script: + # wait for emulator - wait_for_emulator script: ./gradlew clean demo:connectedCheck From bd2a51530f861eaafe6a488a30d01900c551afd9 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Mon, 7 Jul 2014 17:36:51 +0100 Subject: [PATCH 15/22] Update build tools in travis config --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2fa8fb4..ee82d81 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: android android: components: - - build-tools-19.0.3 + - build-tools-19.1.0 before_install: # Create and start emulator @@ -17,7 +17,6 @@ before_install: - uname -a before_script: - # wait for emulator - wait_for_emulator script: ./gradlew clean demo:connectedCheck From 8e2e7abd17c14b93f288ca0d57907d7de1016038 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Mon, 7 Jul 2014 17:52:37 +0100 Subject: [PATCH 16/22] Hopefully fix travis ci --- .travis.yml | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/.travis.yml b/.travis.yml index ee82d81..7bb10a0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,21 +2,13 @@ language: android android: components: - build-tools-19.1.0 - before_install: # Create and start emulator - echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a - - emulator -avd test -no-skin -no-audio -no-window & - - # for gradle output style - - export TERM=dumb - - - # environment info + - emulator -avd test -no-skin -no-audio -no-window + - export TERM=dumb - ./gradlew -v - uname -a - before_script: - - wait_for_emulator - -script: ./gradlew clean demo:connectedCheck + - wait_for_emulator +script: ./gradlew clean demo:connectedCheck \ No newline at end of file From 1c62f1f0be14e1befd1e9b6db02fe5ce0477fe19 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Tue, 8 Jul 2014 10:46:11 +0100 Subject: [PATCH 17/22] Update travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7bb10a0..9119e34 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,7 @@ android: before_install: # Create and start emulator - echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a - - emulator -avd test -no-skin -no-audio -no-window + - emulator -avd test -no-skin -no-audio -no-window & - export TERM=dumb - ./gradlew -v - uname -a From 5c3cae8019ebd52b68de4b3d5a3298f8b2b13000 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Tue, 8 Jul 2014 11:11:15 +0100 Subject: [PATCH 18/22] Add wait_for_emulator script for CI --- wait_for_emulator | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 wait_for_emulator diff --git a/wait_for_emulator b/wait_for_emulator new file mode 100644 index 0000000..e934d70 --- /dev/null +++ b/wait_for_emulator @@ -0,0 +1,21 @@ +#!/bin/bash + +# Originally written by Ralf Kistner , but placed in the public domain + +set +e + +bootanim="" +failcounter=0 +until [[ "$bootanim" =~ "stopped" ]]; do + bootanim=`adb -e shell getprop init.svc.bootanim 2>&1` + echo "$bootanim" + if [[ "$bootanim" =~ "not found" ]]; then + let "failcounter += 1" + if [[ $failcounter -gt 15 ]]; then + echo "Failed to start emulator" + exit 1 + fi + fi + sleep 1 +done +echo "Done" \ No newline at end of file From 9a7be553cf9754efa950ca5b6efbbb3fd554c6c3 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Tue, 8 Jul 2014 11:13:09 +0100 Subject: [PATCH 19/22] Update travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 9119e34..3ed42d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,5 +10,5 @@ before_install: - ./gradlew -v - uname -a before_script: - - wait_for_emulator + - ./wait_for_emulator script: ./gradlew clean demo:connectedCheck \ No newline at end of file From ffefdf55c2b1721b63062872119d432d82584f0d Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Tue, 8 Jul 2014 11:18:27 +0100 Subject: [PATCH 20/22] Change permissions of wait_for_emulator script --- wait_for_emulator | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 wait_for_emulator diff --git a/wait_for_emulator b/wait_for_emulator old mode 100644 new mode 100755 From cfa3ed71373ec8d6aa5e36301b82bf62b3111d25 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Tue, 8 Jul 2014 11:33:50 +0100 Subject: [PATCH 21/22] Update travis config to accept license android-sdk-license-5be876d5 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 3ed42d4..a2e7122 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: android android: components: - build-tools-19.1.0 + licenses: + - android-sdk-license-5be876d5 before_install: # Create and start emulator - echo no | android create avd --force -n test -t android-19 --abi armeabi-v7a From 099d87331b04bfb55349a7ad94ab4229558ce263 Mon Sep 17 00:00:00 2001 From: Ivan Carballo Date: Tue, 8 Jul 2014 11:44:53 +0100 Subject: [PATCH 22/22] Add unit tests to travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a2e7122..acb2999 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ before_install: - uname -a before_script: - ./wait_for_emulator -script: ./gradlew clean demo:connectedCheck \ No newline at end of file +script: ./gradlew clean library:test demo:connectedCheck \ No newline at end of file