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

generator.server.javatool.enums.test.EnumsTest.mustache Maven / Gradle / Ivy

There is a newer version: 1.18.1
Show newest version
package {{ packageName }}.shared.enumeration.domain;

import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.Test;
import {{ packageName }}.UnitTest;
import {{ packageName }}.shared.error.domain.MissingMandatoryValueException;

@UnitTest
class EnumsTest {

  @Test
  void shouldNotMapWithoutTo() {
    assertThatThrownBy(() -> Enums.map(Primary.ONE, null))
      .isExactlyInstanceOf(MissingMandatoryValueException.class)
      .hasMessageContaining("to");
  }

  @Test
  void shouldMapToNullFromNullFrom() {
    assertThat(Enums.map(null, Primary.class)).isNull();
  }

  @Test
  void shouldMapFromPrimaryToDomain() {
    assertThat(Enums.map(Primary.ONE, Domain.class)).isEqualTo(Domain.ONE);
  }

  @Test
  void shouldMapFromDomainToPrimary() {
    assertThat(Enums.map(Domain.ONE, Primary.class)).isEqualTo(Primary.ONE);
  }

  @Test
  void shouldNotMapWithMoreValueInSourceThanDestination() {
    assertThatThrownBy(() -> Enums.map(Other.ONE, Primary.class)).isExactlyInstanceOf(UnmappableEnumException.class);
  }

  @Test
  void shouldMapWithMoreValueInDestinationThanSource() {
    assertThat(Enums.map(Primary.ONE, Other.class)).isEqualTo(Other.ONE);
  }

  private enum Primary {
    ONE,
  }

  private enum Domain {
    ONE,
  }

  private enum Other {
    ONE,
    TWO,
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy