22
33import com .quemb .qmbform .annotation .FormDescriptorAnnotationFactory ;
44import com .quemb .qmbform .annotation .FormElement ;
5+ import com .quemb .qmbform .annotation .FormElementDelegate ;
56import com .quemb .qmbform .annotation .FormOptionsObjectElement ;
67import com .quemb .qmbform .descriptor .FormDescriptor ;
78import com .quemb .qmbform .descriptor .RowDescriptor ;
1718import android .app .Activity ;
1819import android .widget .ListView ;
1920
21+ import java .lang .reflect .Field ;
2022import java .util .Map ;
2123
2224import static junit .framework .Assert .assertTrue ;
2325import static org .hamcrest .MatcherAssert .assertThat ;
2426import static org .hamcrest .core .Is .is ;
27+ import static org .hamcrest .core .IsNull .notNullValue ;
28+ import static org .hamcrest .core .IsNull .nullValue ;
2529
2630/**
2731 * Created by pmaccamp on 9/14/2015.
@@ -32,24 +36,42 @@ public class AnnotationFormTest {
3236 private Activity activity ;
3337 private TestUserClass testUserClass ;
3438
35- public class TestUserClass {
39+ public class TestUserClass implements FormElementDelegate {
3640 @ FormElement (
3741 rowDescriptorType = RowDescriptor .FormRowDescriptorTypeInteger ,
38- required = true
42+ required = true ,
43+ section = android .R .string .unknownName
3944 )
4045 public int age ;
4146
4247 @ FormElement (
4348 rowDescriptorType = RowDescriptor .FormRowDescriptorTypeText ,
44- required = true
49+ required = true ,
50+ section = android .R .string .unknownName
4551 )
4652 public String name ;
4753
54+ @ FormElement (
55+ rowDescriptorType = RowDescriptor .FormRowDescriptorTypeText ,
56+ section = android .R .string .untitled
57+ )
58+ public String option ;
59+
4860
4961 public TestUserClass (int age , String name , int bodyfat ) {
5062 this .age = age ;
5163 this .name = name ;
5264 }
65+
66+ @ Override
67+ public boolean shouldAddRowDescriptorForField (RowDescriptor rowDescriptor , Field field ) {
68+
69+ if (rowDescriptor .getTag ().equals ("option" )){
70+ return this .option != null ;
71+ }
72+
73+ return true ;
74+ }
5375 }
5476
5577 @ Before
@@ -73,6 +95,29 @@ public void hasCorrectFormValues() {
7395 assertThat ((String ) formValues .get ("name" ), is ("John" ));
7496 }
7597
98+ @ Test
99+ public void shouldNotIncludeSection () {
100+
101+ FormDescriptorAnnotationFactory factory = new FormDescriptorAnnotationFactory (activity );
102+ FormDescriptor formDescriptor = factory .createFormDescriptorFromAnnotatedClass (testUserClass );
103+
104+ assertThat (formDescriptor .countOfSections (), is (1 ));
105+ assertThat (formDescriptor .findRowDescriptor ("option" ), nullValue ());
106+
107+ }
108+
109+ @ Test
110+ public void shouldIncludeSection () {
111+
112+ FormDescriptorAnnotationFactory factory = new FormDescriptorAnnotationFactory (activity );
113+ testUserClass .option = "mock" ;
114+ FormDescriptor formDescriptor = factory .createFormDescriptorFromAnnotatedClass (testUserClass );
115+
116+ assertThat (formDescriptor .countOfSections (), is (2 ));
117+ assertThat (formDescriptor .findRowDescriptor ("option" ), notNullValue ());
118+
119+ }
120+
76121 @ After
77122 public void tearDown () {
78123
0 commit comments