Skip to content

tim-group/make-it-easy-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Make-it-easy Templates

A trivial extension to Nat Pryce's make-it-easy library allowing data templates to be defined so that test data can be build using an anonymous block within an anonymous extension class, similar to the style of JMock expectations.

Define your Apple template like this:

public class AppleTemplate extends DataTemplate<Apple, AppleTemplate> {
  public static final Property<Fruit, Double> ripeness = newProperty();
  public static final Property<Apple, Integer> leaves = newProperty();

  @Override
  public Apple build() {
    return make(new Instantiator<Apple>() {
      @Override
      public Apple instantiate(PropertyLookup<Apple> lookup) {
        Apple apple = new Apple(lookup.valueOf(leaves, 2));
        apple.ripen(lookup.valueOf(ripeness, 0.0));
        return apple;
      }
    });
  }
}

Then you can make Apple instances like this:

DataTemplate.derivedFromA(new AppleTemplate() {{
  with(ripeness, 1.0);
  with(leaves, 2);
}});

About

Templates for make-it-easy builders

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published