templates.equalsTestt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JavaForger Show documentation
Show all versions of JavaForger Show documentation
JavaForger can create source code from templates using existing java classes as input.
import java.util.function.BiFunction;
import org.junit.Assert;
import org.junit.Test;
<#include "/test/common/imports.javat">
<#include "/test/common/staticFieldInit.javat">
@Test
public void testEquals_Same() {
${class.name}.Builder builder = createAndFillBuilder();
${class.name} a = builder.build();
${class.name} b = builder.build();
Assert.assertTrue("Expected a and b to be equal", a.equals(b));
}
@Test
public void testEquals_Different() {
<#list fields as field>
verifyEqualsDifferent(${class.name}.Builder::${field.name}, ${field.init2});
#list>
}
private void verifyEqualsDifferent(BiFunction<${class.name}.Builder, T, ${class.name}.Builder> withMapper, T argument) {
${class.name}.Builder builder = createAndFillBuilder();
${class.name} a = builder.build();
${class.name} b = withMapper.apply(builder, argument).build();
Assert.assertFalse("Expected a and b not to be equal", a.equals(b));
}
<#include "/test/common/createAndFillBuilderWithStaticFields.javat">
© 2015 - 2025 Weber Informatics LLC | Privacy Policy