-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test to verify that built-in field adapters can be overridden by cust…
…om adapters. Reaction to #34
- Loading branch information
1 parent
ecca8c7
commit fe8ed9d
Showing
3 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...ry/src/test/java/eu/inmite/android/lib/validations/CustomAdapterForSupportedViewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package eu.inmite.android.lib.validations; | ||
|
||
import android.widget.TextView; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.Robolectric; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
import eu.inmite.android.lib.validations.form.FormValidator; | ||
import eu.inmite.android.lib.validations.form.annotations.MinLength; | ||
import eu.inmite.android.lib.validations.form.annotations.NotEmpty; | ||
import eu.inmite.android.lib.validations.form.iface.IFieldAdapter; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* @author Tomáš Vondráček ([email protected]) on 20/07/15. | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(manifest=Config.NONE) | ||
public class CustomAdapterForSupportedViewTest { | ||
|
||
public static class CustomTextViewAdapter implements IFieldAdapter<TextView, CharSequence> { | ||
|
||
@Override | ||
public String getFieldValue(Annotation annotation, TextView fieldView) { | ||
return fieldView.getText() + "some added text"; | ||
} | ||
} | ||
|
||
private static class ModelWithValidation { | ||
|
||
@NotEmpty | ||
@MinLength(3) | ||
private final TextView view = new TextView(Robolectric.application); | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
FormValidator.registerViewAdapter(TextView.class, CustomTextViewAdapter.class); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
FormValidator.clearViewAdapters(); | ||
} | ||
|
||
@Test | ||
public void customAdapterShouldBeUsed() throws Exception { | ||
final ModelWithValidation model = new ModelWithValidation(); | ||
model.view.setText(""); //adapter will add text and therefore validation should pass | ||
|
||
final boolean valid = FormValidator.validate(Robolectric.application, model, null); | ||
assertTrue(valid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters