package org.immutables.fixture.with;

import org.junit.Test;

import java.math.RoundingMode;
import java.util.Optional;

import static org.immutables.check.Checkers.check;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class WithEnumsTest {
  private static final ImmutableWithEnums TEST_IMMUTABLE = ImmutableWithEnums.builder()
          .roundingMode(RoundingMode.CEILING)
          .maybeRoundingMode(RoundingMode.HALF_DOWN)
          .nullableRoundingMode(RoundingMode.UNNECESSARY)
          .build();
  private static final ImmutableWithEnums TEST_IMMUTABLE_WITH_NULLS = ImmutableWithEnums.builder()
          .roundingMode(RoundingMode.DOWN)
          .maybeRoundingMode(Optional.empty())
          .nullableRoundingMode(null)
          .build();

  @Test
  public void doNotAllowNullEnumValueInNonNullableWith() {
    assertThrows(NullPointerException.class, () -> TEST_IMMUTABLE.withRoundingMode(null));
  }

  @Test
  public void allowNullEnumValueInNullableWith() {
    ImmutableWithEnums withNullableRoundingMode = TEST_IMMUTABLE.withNullableRoundingMode(null);
    check(withNullableRoundingMode.getNullableRoundingMode()).isNull();
  }

  @Test
  public void withOnEqualEnumValueIsSameInstance() {
    check(TEST_IMMUTABLE.withRoundingMode(RoundingMode.CEILING)).same(TEST_IMMUTABLE);
    check(TEST_IMMUTABLE.withMaybeRoundingMode(RoundingMode.HALF_DOWN)).same(TEST_IMMUTABLE);
    check(TEST_IMMUTABLE.withNullableRoundingMode(RoundingMode.UNNECESSARY)).same(TEST_IMMUTABLE);
  }

  @Test
  public void withOnNullEnumValueIsSameInstance() {
    check(TEST_IMMUTABLE_WITH_NULLS.withNullableRoundingMode(null)).same(TEST_IMMUTABLE_WITH_NULLS);
    check(TEST_IMMUTABLE_WITH_NULLS.withMaybeRoundingMode(Optional.empty())).same(TEST_IMMUTABLE_WITH_NULLS);
  }

  @Test
  public void withOnDifferentEnumValueIsNotSameInstance() {
    check(TEST_IMMUTABLE.withRoundingMode(RoundingMode.FLOOR)).not().same(TEST_IMMUTABLE);
    check(TEST_IMMUTABLE.withNullableRoundingMode(RoundingMode.HALF_UP)).not().same(TEST_IMMUTABLE);
    check(TEST_IMMUTABLE.withMaybeRoundingMode(RoundingMode.CEILING)).not().same(TEST_IMMUTABLE);
  }

  @Test
  public void withOnNullEnumValueWithEnumValueIsNotSameInstance() {
    check(TEST_IMMUTABLE_WITH_NULLS.withNullableRoundingMode(RoundingMode.CEILING))
            .not().same(TEST_IMMUTABLE_WITH_NULLS);
    check(TEST_IMMUTABLE_WITH_NULLS.withMaybeRoundingMode(RoundingMode.UNNECESSARY))
            .not().same(TEST_IMMUTABLE_WITH_NULLS);
    check(TEST_IMMUTABLE_WITH_NULLS.withMaybeRoundingMode(Optional.of(RoundingMode.HALF_UP)))
            .not().same(TEST_IMMUTABLE_WITH_NULLS);
  }
}

@@ -48,16 +48,28 @@
 g.junit.
+jupiter.api.
 Test;%0A%0Ai
@@ -2660,11 +2660,1896 @@
 LS);%0A  %7D
+%0A%0A  @Test%0A  public void withOnDifferentEnumValueIsEqualTo() %7B%0A    ImmutableWithEnums testImmutableWithFloorRoundingMode = ImmutableWithEnums.builder()%0A            .roundingMode(RoundingMode.FLOOR)%0A            .maybeRoundingMode(RoundingMode.HALF_DOWN)%0A            .nullableRoundingMode(RoundingMode.UNNECESSARY)%0A            .build();%0A%0A    check(TEST_IMMUTABLE.withRoundingMode(RoundingMode.FLOOR)).is(testImmutableWithFloorRoundingMode);%0A  %7D%0A%0A  @Test%0A  public void withOnNullEnumValueWithEnumValueIsEqualTo() %7B%0A    ImmutableWithEnums testImmutableWithFloorNullableRoundingMode = ImmutableWithEnums.builder()%0A            .roundingMode(RoundingMode.DOWN)%0A            .maybeRoundingMode(Optional.empty())%0A            .nullableRoundingMode(RoundingMode.FLOOR)%0A            .build();%0A%0A    check(TEST_IMMUTABLE_WITH_NULLS.withNullableRoundingMode(RoundingMode.FLOOR))%0A            .is(testImmutableWithFloorNullableRoundingMode);%0A  %7D%0A%0A  @Test%0A  public void withOnOptionalEnumValueWithEnumValueIsEqualTo() %7B%0A    ImmutableWithEnums testImmutableWithHalfDownMaybeRoundingMode = ImmutableWithEnums.builder()%0A            .roundingMode(RoundingMode.DOWN)%0A            .maybeRoundingMode(RoundingMode.HALF_DOWN)%0A            .nullableRoundingMode(null)%0A            .build();%0A%0A    check(TEST_IMMUTABLE_WITH_NULLS.withMaybeRoundingMode(RoundingMode.HALF_DOWN))%0A            .is(testImmutableWithHalfDownMaybeRoundingMode);%0A  %7D%0A%0A  @Test%0A  public void withOnOptionalEnumValueWithEmptyOptionalIsEqualTo() %7B%0A    ImmutableWithEnums testImmutableWithEmptyMaybeRoundingMode = ImmutableWithEnums.builder()%0A            .roundingMode(RoundingMode.CEILING)%0A            .maybeRoundingMode(Optional.empty())%0A            .nullableRoundingMode(RoundingMode.UNNECESSARY)%0A            .build();%0A%0A    check(TEST_IMMUTABLE.withMaybeRoundingMode(Optional.empty()))%0A            .is(testImmutableWithEmptyMaybeRoundingMode);%0A  %7D
 %0A%7D%0A

Add additional tests