Skip to content

Commit

Permalink
Added missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni Möckel committed Feb 24, 2017
1 parent af2ed6a commit 4f9fc74
Show file tree
Hide file tree
Showing 14 changed files with 735 additions and 3 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {

}

}
Original file line number Diff line number Diff line change
@@ -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() {

}

}
Original file line number Diff line number Diff line change
@@ -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<String>("Value"));
rowDescriptor.setDisabled(false);

assertThat( rowDescriptor.getOnFormRowClickListener(), nullValue());

}

@After
public void tearDown() {

}

}
Original file line number Diff line number Diff line change
@@ -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() {

}

}
Original file line number Diff line number Diff line change
@@ -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<Date>(new Date()));
rowDescriptor.setDisabled(true);

FormTimeDialogFieldCell testCell = new FormTimeDialogFieldCell(activity, rowDescriptor);

assertThat(testCell.getTextView().isEnabled(), is(false));

}

@After
public void tearDown() {

}

}
Original file line number Diff line number Diff line change
@@ -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() {

}

}
Loading

0 comments on commit 4f9fc74

Please sign in to comment.