jeudi 23 février 2017

Is there any library provide automatic test case for a java builder pattern?

We are using lombok auto generated code. Also we are using SonarCube to monitor the code coverage.

There are libraries like meanbean and equalsverfier could be used for getter, setter testing. But they did not cover the builder pattern.

Also sometimes the Json object mapper need us to define an empty builder for serialization / deserialization.

I wonder if there are any public libraries could be used to cover these code for builder pattern.

For example, I have a status bean looks like :

@JsonDeserialize(builder = Status.StatusBuilder.class)
@Builder
@Data
@SuppressWarnings("PMD.UnusedPrivateField")
public class Status {
    private String version;
    ......
    private String country;
    private String timeZone;

    //The annotation is used for force JSON serializer/deserializer to use builder pattern to do object mapping.
    @JsonPOJOBuilder(withPrefix = "")
    public static final class StatusBuilder {
    }
}

To test getter / setter things, I could use the following from package meanbean and equalsverfier. But we have no idea about how to cover the lombok generated builder and Json StatusBuilder. public class StatusTest {

@Test
public void testGetterSetterToString() throws Exception {
    new BeanTester().testBean(Status.class);
}

@Test
public void testEqualsAndHashCode() throws Exception {
    EqualsVerifier.forClass(Status.class).withRedefinedSuperclass()
            .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).verify();
}
}

Aucun commentaire:

Enregistrer un commentaire