templates.hashCodeTestt 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 testHashCode_Same() {
${class.name}.Builder builder = createAndFillBuilder();
${class.name} a = builder.build();
${class.name} b = builder.build();
Assert.assertEquals("Expected hash code to be the same", a.hashCode(), b.hashCode());
}
@Test
public void testHashCode_Different() {
<#list fields as field>
verifyHashCode_Different(${class.name}.Builder::${field.name}, ${field.init2});
#list>
}
private void verifyHashCode_Different(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.assertNotEquals("Expected hash code to be different", a.hashCode(), b.hashCode());
}
<#include "/test/common/createAndFillBuilderWithStaticFields.javat">
© 2015 - 2025 Weber Informatics LLC | Privacy Policy