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

templates.equalsTestt 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 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});

  }

  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