All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.hashCodeTestt Maven / Gradle / Ivy

Go to download

JavaForger can create source code from templates using existing java classes as input.

There is a newer version: 2.0.1
Show newest version
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});

  }

  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