From 60df69f88ff50fab3e387b01cf269fd69f79369a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Mo=CC=88ckel?= Date: Thu, 2 Mar 2017 10:50:21 +0100 Subject: [PATCH] Fixed Unit Tests --- lib/QMBForm/build.gradle | 13 ++-- .../quemb/qmbform/view/FormDateFieldCell.java | 3 +- .../com/quemb/qmbform/AnnotationFormTest.java | 4 +- .../qmbform/FormBooleanFieldCellTest.java | 4 +- .../qmbform/FormButtonFieldCellTest.java | 4 +- .../quemb/qmbform/FormCheckFieldCellTest.java | 4 +- .../quemb/qmbform/FormDateFieldCellTest.java | 4 +- .../quemb/qmbform/FormEditFieldCellTest.java | 4 +- .../qmbform/FormIntegerSliderCellTest.java | 4 +- .../com/quemb/qmbform/FormManagerTest.java | 4 +- .../qmbform/FormPickerFieldCellTest.java | 4 +- ...SelectorSegmentedControlFieldCellTest.java | 59 ------------------- .../com/quemb/qmbform/ValidationTest.java | 2 +- .../java/com/quemb/qmbform/ValueTest.java | 4 +- .../quemb/qmbform/view/FormBaseCellTest.java | 4 +- .../com/quemb/qmbform/robolectric.properties | 3 + 16 files changed, 35 insertions(+), 89 deletions(-) delete mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormSelectorSegmentedControlFieldCellTest.java create mode 100644 lib/QMBForm/src/test/resources/com/quemb/qmbform/robolectric.properties diff --git a/lib/QMBForm/build.gradle b/lib/QMBForm/build.gradle index deeb810..48bca3d 100755 --- a/lib/QMBForm/build.gradle +++ b/lib/QMBForm/build.gradle @@ -39,12 +39,9 @@ android { lintOptions { abortOnError false } + sourceSets { - androidTest { - setRoot('src/test') - res.srcDirs = [ 'src/test/resources' ] - } - + test { setRoot('src/test') res.srcDirs = [ 'src/test/resources' ] @@ -57,6 +54,9 @@ android { abortOnError false } + testOptions { + unitTests.returnDefaultValues = true + } } dependencies { @@ -65,7 +65,8 @@ dependencies { testCompile 'junit:junit:4.12' testCompile 'org.hamcrest:hamcrest-core:1.2.1' - testCompile 'org.robolectric:robolectric:3.0' + testCompile "org.robolectric:robolectric:3.2.2" + } apply plugin: 'idea' diff --git a/lib/QMBForm/src/main/java/com/quemb/qmbform/view/FormDateFieldCell.java b/lib/QMBForm/src/main/java/com/quemb/qmbform/view/FormDateFieldCell.java index f1ab857..fec5d0e 100755 --- a/lib/QMBForm/src/main/java/com/quemb/qmbform/view/FormDateFieldCell.java +++ b/lib/QMBForm/src/main/java/com/quemb/qmbform/view/FormDateFieldCell.java @@ -45,6 +45,7 @@ protected void update() { String title = getFormItemDescriptor().getTitle(); mTextView.setText(title); mTextView.setVisibility(title == null ? GONE : VISIBLE); + mTextView.setEnabled(!getRowDescriptor().getDisabled()); @SuppressWarnings("unchecked") Value value = (Value) getRowDescriptor().getValue(); if (value == null || value.getValue() == null) { @@ -79,7 +80,7 @@ public void onDateChanged(Date date) { // calendar.set(year, monthOfYear, dayOfMonth); // Date date = new Date(calendar.getTimeInMillis()); - updateDateLabel(date, false); + updateDateLabel(date, getRowDescriptor().getDisabled()); onValueChanged(new Value(date)); diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/AnnotationFormTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/AnnotationFormTest.java index 6d74139..828602b 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/AnnotationFormTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/AnnotationFormTest.java @@ -11,7 +11,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -27,7 +27,7 @@ * Created by pmaccamp on 9/14/2015. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class AnnotationFormTest { private Activity activity; private TestUserClass testUserClass; diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormBooleanFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormBooleanFieldCellTest.java index 92eb5e7..440e86c 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormBooleanFieldCellTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormBooleanFieldCellTest.java @@ -8,7 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -20,7 +20,7 @@ * Created by tonimoeckel on 02.09.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormBooleanFieldCellTest { diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormButtonFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormButtonFieldCellTest.java index 8e4a4ee..60fd519 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormButtonFieldCellTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormButtonFieldCellTest.java @@ -8,7 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -20,7 +20,7 @@ * Created by tonimoeckel on 02.09.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormButtonFieldCellTest { private Activity activity; diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormCheckFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormCheckFieldCellTest.java index bf9cc18..e081a45 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormCheckFieldCellTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormCheckFieldCellTest.java @@ -8,7 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -20,7 +20,7 @@ * Created by tonimoeckel on 02.09.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormCheckFieldCellTest { diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormDateFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormDateFieldCellTest.java index f8ceea5..0d3ee7f 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormDateFieldCellTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormDateFieldCellTest.java @@ -9,7 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -23,7 +23,7 @@ * Created by tonimoeckel on 02.09.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormDateFieldCellTest { diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormEditFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormEditFieldCellTest.java index 946bb9d..c90abab 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormEditFieldCellTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormEditFieldCellTest.java @@ -8,7 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -20,7 +20,7 @@ * Created by tonimoeckel on 02.09.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormEditFieldCellTest { diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormIntegerSliderCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormIntegerSliderCellTest.java index 7a48152..b07e802 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormIntegerSliderCellTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormIntegerSliderCellTest.java @@ -9,7 +9,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -21,7 +21,7 @@ * Created by tonimoeckel on 02.09.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormIntegerSliderCellTest { diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormManagerTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormManagerTest.java index 07c25b6..002c9df 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormManagerTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormManagerTest.java @@ -7,7 +7,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -21,7 +21,7 @@ * Created by tonimoeckel on 12.08.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormManagerTest { private FormManager formManager; diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormPickerFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormPickerFieldCellTest.java index e9d6332..3b1f58a 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormPickerFieldCellTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormPickerFieldCellTest.java @@ -8,7 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -20,7 +20,7 @@ * Created by tonimoeckel on 02.09.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormPickerFieldCellTest { diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormSelectorSegmentedControlFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormSelectorSegmentedControlFieldCellTest.java deleted file mode 100755 index f1acb1c..0000000 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormSelectorSegmentedControlFieldCellTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.quemb.qmbform; - -import com.quemb.qmbform.descriptor.FormOptionsObject; -import com.quemb.qmbform.descriptor.RowDescriptor; -import com.quemb.qmbform.descriptor.Value; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; -import org.robolectric.annotation.Config; - -import java.util.ArrayList; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.hamcrest.core.IsNull.notNullValue; - -/** - * Created by pmaccamp on 9/14/2015. - */ -@Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) -public class FormSelectorSegmentedControlFieldCellTest { - - @Before - public void setUp() { - } - - @Test - public void hasCorrectSegmentSelected() { - RowDescriptor rowDescriptor = RowDescriptor.newInstance("segmented", - RowDescriptor.FormRowDescriptorTypeSelectorSegmentedControl, - "Segmented Control Test", - new Value("1")); - - ArrayList selectorOptions = new ArrayList(); - selectorOptions.add(FormOptionsObject.createFormOptionsObject("0", "Test 0")); - selectorOptions.add(FormOptionsObject.createFormOptionsObject("1", "Test 1")); - selectorOptions.add(FormOptionsObject.createFormOptionsObject("2", "Test 2")); - - rowDescriptor.setSelectorOptions(selectorOptions); - - assertThat(rowDescriptor, is(notNullValue())); - // Check that value exists in selector options - FormOptionsObject selected = FormOptionsObject.formOptionsObjectFromArrayWithValue( - rowDescriptor.getValueData(), selectorOptions); - assertThat(selected.getDisplayText(), - is("Test 1")); - - } - - @After - public void tearDown() { - - } - -} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/ValidationTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/ValidationTest.java index 0d2a3af..55b1f6c 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/ValidationTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/ValidationTest.java @@ -18,7 +18,7 @@ */ // @Config(constants = BuildConfig.class) -// @RunWith(RobolectricGradleTestRunner.class) +// @RunWith(RobolectricTestRunner.class) public class ValidationTest { @Before public void setUp() { diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/ValueTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/ValueTest.java index c8a30cb..ad6772a 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/ValueTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/ValueTest.java @@ -7,7 +7,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import static org.hamcrest.MatcherAssert.assertThat; @@ -17,7 +17,7 @@ * Created by tonimoeckel on 28.08.14. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class ValueTest { private Value value; diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/view/FormBaseCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/view/FormBaseCellTest.java index 4c443c8..ab7c3f4 100755 --- a/lib/QMBForm/src/test/java/com/quemb/qmbform/view/FormBaseCellTest.java +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/view/FormBaseCellTest.java @@ -8,7 +8,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.robolectric.Robolectric; -import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.RobolectricTestRunner; import org.robolectric.annotation.Config; import android.app.Activity; @@ -20,7 +20,7 @@ * Created by Toni on 25.10.15. */ @Config(constants = BuildConfig.class) -@RunWith(RobolectricGradleTestRunner.class) +@RunWith(RobolectricTestRunner.class) public class FormBaseCellTest { FormBaseCell cell; diff --git a/lib/QMBForm/src/test/resources/com/quemb/qmbform/robolectric.properties b/lib/QMBForm/src/test/resources/com/quemb/qmbform/robolectric.properties new file mode 100644 index 0000000..81e279f --- /dev/null +++ b/lib/QMBForm/src/test/resources/com/quemb/qmbform/robolectric.properties @@ -0,0 +1,3 @@ +sdk=18 +manifest=lib/QMBForm/src/main/AndroidManifest.xml +constants=com.quemb.qmbform.BuildConfig \ No newline at end of file