package org.immutables.fixture.with;

import org.junit.Test;

import java.math.RoundingMode;

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();

  @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();
  }
}

@@ -85,16 +85,43 @@
 ingMode;
+%0Aimport java.util.Optional;
 %0A%0Aimport
@@ -520,16 +520,263 @@
 build();
+%0A  private static final ImmutableWithEnums TEST_IMMUTABLE_WITH_NULLS = ImmutableWithEnums.builder()%0A          .roundingMode(RoundingMode.DOWN)%0A          .maybeRoundingMode(Optional.empty())%0A          .nullableRoundingMode(null)%0A          .build();
 %0A%0A  @Tes
@@ -1088,16 +1088,16 @@
 (null);%0A
-
     chec
@@ -1163,11 +1163,1496 @@
 l();%0A  %7D
+%0A%0A  @Test%0A  public void withOnEqualEnumValueIsSameInstance() %7B%0A    check(TEST_IMMUTABLE.withRoundingMode(RoundingMode.CEILING)).same(TEST_IMMUTABLE);%0A    check(TEST_IMMUTABLE.withMaybeRoundingMode(RoundingMode.HALF_DOWN)).same(TEST_IMMUTABLE);%0A    check(TEST_IMMUTABLE.withNullableRoundingMode(RoundingMode.UNNECESSARY)).same(TEST_IMMUTABLE);%0A  %7D%0A%0A  @Test%0A  public void withOnNullEnumValueIsSameInstance() %7B%0A    check(TEST_IMMUTABLE_WITH_NULLS.withNullableRoundingMode(null)).same(TEST_IMMUTABLE_WITH_NULLS);%0A    check(TEST_IMMUTABLE_WITH_NULLS.withMaybeRoundingMode(Optional.empty())).same(TEST_IMMUTABLE_WITH_NULLS);%0A  %7D%0A%0A  @Test%0A  public void withOnDifferentEnumValueIsNotSameInstance() %7B%0A    check(TEST_IMMUTABLE.withRoundingMode(RoundingMode.FLOOR)).not().same(TEST_IMMUTABLE);%0A    check(TEST_IMMUTABLE.withNullableRoundingMode(RoundingMode.HALF_UP)).not().same(TEST_IMMUTABLE);%0A    check(TEST_IMMUTABLE.withMaybeRoundingMode(RoundingMode.CEILING)).not().same(TEST_IMMUTABLE);%0A  %7D%0A%0A  @Test%0A  public void withOnNullEnumValueWithEnumValueIsNotSameInstance() %7B%0A    check(TEST_IMMUTABLE_WITH_NULLS.withNullableRoundingMode(RoundingMode.CEILING))%0A            .not().same(TEST_IMMUTABLE_WITH_NULLS);%0A    check(TEST_IMMUTABLE_WITH_NULLS.withMaybeRoundingMode(RoundingMode.UNNECESSARY))%0A            .not().same(TEST_IMMUTABLE_WITH_NULLS);%0A    check(TEST_IMMUTABLE_WITH_NULLS.withMaybeRoundingMode(Optional.of(RoundingMode.HALF_UP)))%0A            .not().same(TEST_IMMUTABLE_WITH_NULLS);%0A  %7D
 %0A%7D%0A

Add tests to validate returned with(enum) instances