From 4f9fc74db81bfc6b4a6c603e1791e450e88116ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Mo=CC=88ckel?= Date: Fri, 24 Feb 2017 16:18:51 +0100 Subject: [PATCH] Added missing tests --- .travis.yml | 6 +- .../com/quemb/qmbform/AnnotationFormTest.java | 81 +++++++++++++++++++ .../qmbform/FormBooleanFieldCellTest.java | 51 ++++++++++++ .../qmbform/FormButtonFieldCellTest.java | 47 +++++++++++ .../quemb/qmbform/FormCheckFieldCellTest.java | 51 ++++++++++++ .../quemb/qmbform/FormDateFieldCellTest.java | 53 ++++++++++++ .../quemb/qmbform/FormEditFieldCellTest.java | 51 ++++++++++++ .../qmbform/FormIntegerSliderCellTest.java | 52 ++++++++++++ .../com/quemb/qmbform/FormManagerTest.java | 52 ++++++++++++ .../qmbform/FormPickerFieldCellTest.java | 51 ++++++++++++ ...SelectorSegmentedControlFieldCellTest.java | 59 ++++++++++++++ .../com/quemb/qmbform/ValidationTest.java | 75 +++++++++++++++++ .../java/com/quemb/qmbform/ValueTest.java | 52 ++++++++++++ .../quemb/qmbform/view/FormBaseCellTest.java | 57 +++++++++++++ 14 files changed, 735 insertions(+), 3 deletions(-) create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/AnnotationFormTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormBooleanFieldCellTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormButtonFieldCellTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormCheckFieldCellTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormDateFieldCellTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormEditFieldCellTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormIntegerSliderCellTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormManagerTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormPickerFieldCellTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/FormSelectorSegmentedControlFieldCellTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/ValidationTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/ValueTest.java create mode 100755 lib/QMBForm/src/test/java/com/quemb/qmbform/view/FormBaseCellTest.java diff --git a/.travis.yml b/.travis.yml index faaaa99..d413684 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,17 +7,17 @@ android: - tools # The BuildTools version used by your project - - build-tools-23.0.2 + - build-tools-25.0.2 # The SDK version used to compile your project - - android-23 + - android-25 # Design Support Library - extra-android-m2repository # Specify at least one system image, # if you need to run emulator(s) during your tests - - sys-img-armeabi-v7a-android-23 + - sys-img-armeabi-v7a-android-25 before_install: - chmod +x gradlew diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/AnnotationFormTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/AnnotationFormTest.java new file mode 100755 index 0000000..6d74139 --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/AnnotationFormTest.java @@ -0,0 +1,81 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.annotation.FormDescriptorAnnotationFactory; +import com.quemb.qmbform.annotation.FormElement; +import com.quemb.qmbform.annotation.FormOptionsObjectElement; +import com.quemb.qmbform.descriptor.FormDescriptor; +import com.quemb.qmbform.descriptor.RowDescriptor; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; +import android.widget.ListView; + +import java.util.Map; + +import static junit.framework.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by pmaccamp on 9/14/2015. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class AnnotationFormTest { + private Activity activity; + private TestUserClass testUserClass; + + public class TestUserClass { + @FormElement( + rowDescriptorType = RowDescriptor.FormRowDescriptorTypeInteger, + required = true + ) + public int age; + + @FormElement( + rowDescriptorType = RowDescriptor.FormRowDescriptorTypeText, + required = true + ) + public String name; + + + public TestUserClass(int age, String name, int bodyfat) { + this.age = age; + this.name = name; + } + } + + @Before + public void setUp() { + activity = Robolectric.buildActivity(Activity.class).create().get(); + testUserClass = new TestUserClass(25, "John", 10); + } + + @Test + public void hasCorrectFormValues() { + FormDescriptorAnnotationFactory factory = new FormDescriptorAnnotationFactory(activity); + FormDescriptor formDescriptor = factory.createFormDescriptorFromAnnotatedClass(testUserClass); + + final FormManager formManager = new FormManager(); + ListView listView = new ListView(activity); + formManager.setup(formDescriptor, listView, activity); + + Map formValues = formDescriptor.getFormValues(); + + assertThat((int) formValues.get("age"), is(25)); + assertThat((String) formValues.get("name"), is("John")); + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormBooleanFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormBooleanFieldCellTest.java new file mode 100755 index 0000000..92eb5e7 --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormBooleanFieldCellTest.java @@ -0,0 +1,51 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.descriptor.RowDescriptor; +import com.quemb.qmbform.view.FormBooleanFieldCell; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by tonimoeckel on 02.09.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormBooleanFieldCellTest { + + + private Activity activity; + + @Before + public void setUp() { + activity = Robolectric.buildActivity(Activity.class).create().get(); + } + + @Test + public void shouldBeDisabled(){ + + RowDescriptor rowDescriptor = RowDescriptor.newInstance("disabled", RowDescriptor.FormRowDescriptorTypeBooleanSwitch); + rowDescriptor.setDisabled(true); + + FormBooleanFieldCell testCell = new FormBooleanFieldCell(activity, rowDescriptor); + + assertThat(testCell.getSwitch().isEnabled(), is(false)); + + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormButtonFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormButtonFieldCellTest.java new file mode 100755 index 0000000..8e4a4ee --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormButtonFieldCellTest.java @@ -0,0 +1,47 @@ +package com.quemb.qmbform; + +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.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.IsNull.nullValue; + +/** + * Created by tonimoeckel on 02.09.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormButtonFieldCellTest { + private Activity activity; + + @Before + public void setUp() { + activity = Robolectric.buildActivity(Activity.class).create().get(); + } + + @Test + public void shouldBeDisabled(){ + + RowDescriptor rowDescriptor = RowDescriptor.newInstance("pickerDisabled",RowDescriptor.FormRowDescriptorTypeSelectorPickerDialog, "Picker Disabled", new Value("Value")); + rowDescriptor.setDisabled(false); + + assertThat( rowDescriptor.getOnFormRowClickListener(), nullValue()); + + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormCheckFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormCheckFieldCellTest.java new file mode 100755 index 0000000..bf9cc18 --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormCheckFieldCellTest.java @@ -0,0 +1,51 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.descriptor.RowDescriptor; +import com.quemb.qmbform.view.FormCheckFieldCell; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by tonimoeckel on 02.09.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormCheckFieldCellTest { + + + private Activity activity; + + @Before + public void setUp() { + activity = Robolectric.buildActivity(Activity.class).create().get(); + } + + @Test + public void shouldBeDisabled(){ + + RowDescriptor rowDescriptor = RowDescriptor.newInstance("disabled", RowDescriptor.FormRowDescriptorTypeBooleanCheck); + rowDescriptor.setDisabled(true); + + FormCheckFieldCell testCell = new FormCheckFieldCell(activity, rowDescriptor); + + assertThat(testCell.getCheckBox().isEnabled(), is(false)); + + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormDateFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormDateFieldCellTest.java new file mode 100755 index 0000000..f8ceea5 --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormDateFieldCellTest.java @@ -0,0 +1,53 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.descriptor.RowDescriptor; +import com.quemb.qmbform.descriptor.Value; +import com.quemb.qmbform.view.FormTimeDialogFieldCell; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; + +import java.util.Date; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by tonimoeckel on 02.09.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormDateFieldCellTest { + + + private Activity activity; + + @Before + public void setUp() { + activity = Robolectric.buildActivity(Activity.class).create().get(); + } + + @Test + public void shouldBeDisabled(){ + RowDescriptor rowDescriptor = RowDescriptor.newInstance("timeDialog",RowDescriptor.FormRowDescriptorTypeTime, "Time Dialog", new Value(new Date())); + rowDescriptor.setDisabled(true); + + FormTimeDialogFieldCell testCell = new FormTimeDialogFieldCell(activity, rowDescriptor); + + assertThat(testCell.getTextView().isEnabled(), is(false)); + + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormEditFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormEditFieldCellTest.java new file mode 100755 index 0000000..946bb9d --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormEditFieldCellTest.java @@ -0,0 +1,51 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.descriptor.RowDescriptor; +import com.quemb.qmbform.view.FormEditIntegerFieldCell; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by tonimoeckel on 02.09.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormEditFieldCellTest { + + + private Activity activity; + + @Before + public void setUp() { + activity = Robolectric.buildActivity(Activity.class).create().get(); + } + + @Test + public void shouldBeDisabled(){ + + RowDescriptor rowDescriptor = RowDescriptor.newInstance("disabled", RowDescriptor.FormRowDescriptorTypeInteger); + rowDescriptor.setDisabled(true); + + FormEditIntegerFieldCell testCell = new FormEditIntegerFieldCell(activity, rowDescriptor); + + assertThat(testCell.getEditText().isEnabled(), is(false)); + + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormIntegerSliderCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormIntegerSliderCellTest.java new file mode 100755 index 0000000..7a48152 --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormIntegerSliderCellTest.java @@ -0,0 +1,52 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.descriptor.RowDescriptor; +import com.quemb.qmbform.descriptor.Value; +import com.quemb.qmbform.view.FormIntegerSliderFieldCell; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by tonimoeckel on 02.09.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormIntegerSliderCellTest { + + + private Activity activity; + + @Before + public void setUp() { + activity = Robolectric.buildActivity(Activity.class).create().get(); + } + + @Test + public void shouldBeDisabled(){ + + RowDescriptor rowDescriptor = RowDescriptor.newInstance("integerSlider",RowDescriptor.FormRowDescriptorTypeIntegerSlider, "Integer Slider", new Value(50)); + rowDescriptor.setDisabled(true); + + FormIntegerSliderFieldCell testCell = new FormIntegerSliderFieldCell(activity, rowDescriptor); + + assertThat(testCell.getSeekBar().isEnabled(), is(false)); + + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormManagerTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormManagerTest.java new file mode 100755 index 0000000..07c25b6 --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormManagerTest.java @@ -0,0 +1,52 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.descriptor.FormDescriptor; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; +import android.widget.ListView; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; +import static org.hamcrest.core.IsNull.notNullValue; + +/** + * Created by tonimoeckel on 12.08.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormManagerTest { + + private FormManager formManager; + private Activity activity; + + @Before + public void setUp() { + formManager = new FormManager(); + activity = Robolectric.buildActivity(Activity.class).create().get(); + } + + @Test + public void shouldSetupListView(){ + + ListView listView = new ListView(activity); + FormDescriptor formDescriptor = new FormDescriptor(); + formManager.setup(formDescriptor, listView, activity); + + assertThat(listView.getAdapter(), is(notNullValue())); + + } + + @After + public void tearDown() { + + } + +} \ No newline at end of file diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormPickerFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormPickerFieldCellTest.java new file mode 100755 index 0000000..e9d6332 --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormPickerFieldCellTest.java @@ -0,0 +1,51 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.descriptor.RowDescriptor; +import com.quemb.qmbform.view.FormPickerDialogFieldCell; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by tonimoeckel on 02.09.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormPickerFieldCellTest { + + + private Activity activity; + + @Before + public void setUp() { + activity = Robolectric.buildActivity(Activity.class).create().get(); + } + + @Test + public void shouldBeDisabled(){ + + RowDescriptor rowDescriptor = RowDescriptor.newInstance("picker",RowDescriptor.FormRowDescriptorTypeButton, "Tap Me"); + rowDescriptor.setDisabled(true); + + FormPickerDialogFieldCell testCell = new FormPickerDialogFieldCell(activity, rowDescriptor); + + assertThat( testCell.getTextView().isClickable(), is(false)); + + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/FormSelectorSegmentedControlFieldCellTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormSelectorSegmentedControlFieldCellTest.java new file mode 100755 index 0000000..f1acb1c --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/FormSelectorSegmentedControlFieldCellTest.java @@ -0,0 +1,59 @@ +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 new file mode 100755 index 0000000..0d2a3af --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/ValidationTest.java @@ -0,0 +1,75 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.annotation.FormValidator; +import com.quemb.qmbform.annotation.validators.EmailValidator; +import com.quemb.qmbform.descriptor.RowDescriptor; +import com.quemb.qmbform.descriptor.RowValidationError; +import com.quemb.qmbform.descriptor.Value; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by pmaccamp on 9/14/2015. + */ + +// @Config(constants = BuildConfig.class) +// @RunWith(RobolectricGradleTestRunner.class) +public class ValidationTest { + @Before + public void setUp() { + + } + + @Test + public void isValidRow() { + RowDescriptor rowDescriptor = RowDescriptor.newInstance("valid", + RowDescriptor.FormRowDescriptorTypeEmail, + "Email Test", + new Value("test@yahoo.com")); + + rowDescriptor.addValidator(new EmailValidator()); + + //Add true dummy validator to test multiple validation + rowDescriptor.addValidator(new FormValidator() { + @Override + public RowValidationError validate(RowDescriptor descriptor) { + return descriptor.getValueData().equals("test@yahoo.com") ? + null : new RowValidationError(descriptor, R.string.test_error); + } + }); + + assertThat(rowDescriptor.isValid(), is(true)); + } + + @Test + public void isInvalidRow() { + RowDescriptor rowDescriptor = RowDescriptor.newInstance("valid", + RowDescriptor.FormRowDescriptorTypeEmail, + "Email Test", + new Value("notavalidemail")); + + //Add true dummy validator to test multiple validation + rowDescriptor.addValidator(new FormValidator() { + @Override + public RowValidationError validate(RowDescriptor descriptor) { + return descriptor.getValueData().equals("notavalidemail") ? + null : new RowValidationError(descriptor, R.string.test_error); + } + }); + + rowDescriptor.addValidator(new EmailValidator()); + + assertThat(rowDescriptor.isValid(), is(false)); + } + + @After + public void tearDown() { + + } + +} diff --git a/lib/QMBForm/src/test/java/com/quemb/qmbform/ValueTest.java b/lib/QMBForm/src/test/java/com/quemb/qmbform/ValueTest.java new file mode 100755 index 0000000..c8a30cb --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/ValueTest.java @@ -0,0 +1,52 @@ +package com.quemb.qmbform; + +import com.quemb.qmbform.descriptor.OnValueChangeListener; +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 static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +/** + * Created by tonimoeckel on 28.08.14. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class ValueTest { + + private Value value; + private Integer resultInt = 0; + + @Before + public void setUp() { + value = new Value(50); + } + + @Test + public void shouldCallListener() { + + OnValueChangeListener listener = new OnValueChangeListener() { + @Override + public void onChange(Integer value) { + resultInt = value; + } + }; + value.setOnValueChangeListener(listener); + value.setValue(100); + + assertThat(resultInt, is(100)); + + } + + @After + public void tearDown() { + + } + +} \ No newline at end of file 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 new file mode 100755 index 0000000..4c443c8 --- /dev/null +++ b/lib/QMBForm/src/test/java/com/quemb/qmbform/view/FormBaseCellTest.java @@ -0,0 +1,57 @@ +package com.quemb.qmbform.view; + +import com.quemb.qmbform.BuildConfig; +import com.quemb.qmbform.descriptor.RowDescriptor; +import com.quemb.qmbform.descriptor.SectionDescriptor; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.Robolectric; +import org.robolectric.RobolectricGradleTestRunner; +import org.robolectric.annotation.Config; + +import android.app.Activity; +import android.inputmethodservice.Keyboard; + +import static org.junit.Assert.*; + +/** + * Created by Toni on 25.10.15. + */ +@Config(constants = BuildConfig.class) +@RunWith(RobolectricGradleTestRunner.class) +public class FormBaseCellTest { + + FormBaseCell cell; + + @Before + public void setUp() throws Exception { + + Activity activity = Robolectric.buildActivity(Activity.class).create().get(); + SectionDescriptor sectionDescriptor = SectionDescriptor.newInstance("test"); + RowDescriptor rowDescriptor = RowDescriptor.newInstance("sample"); + sectionDescriptor.addRow(rowDescriptor); + cell = new FormBaseCell(activity,rowDescriptor) { + @Override + protected int getResource() { + return 0; + } + + @Override + protected void update() { + + } + }; + + } + + @Test + public void testShouldCreateMultiValueWrapper() { + + + assertNotNull(cell.createMultiValueWrapper()); + + + } +} \ No newline at end of file