Skip to content

Commit

Permalink
enable setting class populator
Browse files Browse the repository at this point in the history
  • Loading branch information
eddmash committed Jun 6, 2018
1 parent 7488d50 commit 7e7ed50
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
21 changes: 12 additions & 9 deletions form/src/main/java/com/eddmash/form/faker/DummyDataPopulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,23 @@ public class DummyDataPopulator implements PopulatorInterface {
private Guess guesser;
private Map<String, ProviderInterface> fieldPopulators;
private boolean populationComplete = false;
private Map<Class, ProviderInterface> classPopulators;


public DummyDataPopulator() {
fieldPopulators = new HashMap<>();
classPopulators = new HashMap<>();
guesser = new Guess(this);
}

public void setFieldProvider(String name, ProviderInterface provider) {
fieldPopulators.put(name, provider);
}

public void setFieldProvider(Class clazz, ProviderInterface provider) {
classPopulators.put(clazz, provider);
}

public void populate(FormInterface form) throws FormException {
if (!populationComplete) {

Expand Down Expand Up @@ -101,17 +107,14 @@ public void populate(FieldInterface field) throws FormException {

private String generateData(String fieldName, View field) throws
FormException {

if (fieldPopulators.containsKey(fieldName)) {
try {
try {
if (fieldPopulators.containsKey(fieldName)) {
return String.valueOf(fieldPopulators.get(fieldName).getData());
} catch (Exception e) {
e.printStackTrace();
Log.e(
getClass().getName(),
e.getMessage() + " :: Falling back to guessing"
);
} else if (classPopulators.containsKey(field.getClass())) {
return String.valueOf(classPopulators.get(field.getClass()).getData());
}
} catch (Exception e) {
// just ignore this and continue proccessing
}

if (field instanceof EditText) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.util.regex.Pattern;

/**
* VAlidate a view against the provided rule or pattern
* VAlidate a view against the provided rule or pattern.
* <p>
* Validation will fail if the view value does not match the provided pattern.
*/
public class RegexCheck extends CheckSingle {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.eddmash.validation.checks;

import android.widget.TextView;

/**
* Enables comparing different view values.
*/
public interface ViewComparisonInterface extends CheckInterface {

void addView(TextView v);

void removeView(TextView v);
}

0 comments on commit 7e7ed50

Please sign in to comment.