Skip to main content

Building models for Tests

When using expanders-assert

You do not have to call the test model builder directly yourself, instead you return the spec from a @TestModel method. See the expanders-assert docs for more info.

You can build a model using the TestModelBuilder class

private final TestModelBuilder modelBuilder = new TestModelBuilder();

private ComponentComposite baseModel() {
return modelBuilder.buildModel(
component("testComp",
dataElement("City")));
}

To build a Component model, you can use the buildModel(spec) method:

modelBuilder.buildModel(
component("testComp",
dataElement("City")));

You can also build a Component and select a DataElement with the buildModelAndFind(spec, selector) method:

modelBuilder.buildModelAndFind(
component("testComp",
dataElement("City")),
dataElement("testComp::City"));

Alternatively, you can pass an ApplicationSpec to build an Application model:

modelBuilder.buildModel(
application("testApp",
component("testComp",
dataElement("City"))));

The TestModelBuilder uses the Onion Spec API to define the test models.