diff --git a/src/main/java/tech/jhipster/lite/shared/error/domain/UnauthorizedValueException.java b/src/main/java/tech/jhipster/lite/shared/error/domain/UnauthorizedValueException.java deleted file mode 100644 index 463a414adb3..00000000000 --- a/src/main/java/tech/jhipster/lite/shared/error/domain/UnauthorizedValueException.java +++ /dev/null @@ -1,54 +0,0 @@ -package tech.jhipster.lite.shared.error.domain; - -public class UnauthorizedValueException extends RuntimeException { - - public UnauthorizedValueException(String field) { - this(new RuntimeException(defaultMessage(field))); - } - - public UnauthorizedValueException(RuntimeException runtimeException) { - super(runtimeException.getMessage()); - } - - private static String defaultMessage(String field) { - return "The field \"" + field + "\" was given an unauthorized value"; - } - - public static UnauthorizedValueException forNegativeValue(String field) { - return new UnauthorizedValueException(new RuntimeException(defaultMessage(field) + " (negative)")); - } - - public static UnauthorizedValueException forInconsistentValue(String field, Object input) { - return new UnauthorizedValueException(new RuntimeException(defaultMessage(field) + " (inconsistent : " + input.toString() + ")")); - } - - public static UnauthorizedValueException forInconsistentValues(String field1, Object input1, String field2, Object input2) { - return new UnauthorizedValueException( - new RuntimeException(defaultMessage(field2) + " (" + input2 + " which is inconsistent with \"" + field1 + "\" : " + input1 + ")") - ); - } - - public static UnauthorizedValueException forUnequalValues(String field1, String field2, Object input1, Object input2) { - return new UnauthorizedValueException( - new RuntimeException(defaultMessage(field2) + " (" + input2 + " not equal with field \"" + field1 + "\" : " + input1.toString() + ")") - ); - } - - public static UnauthorizedValueException forUnexpectedType(String field) { - return new UnauthorizedValueException(new RuntimeException(defaultMessage(field) + " (unexpected type)")); - } - - public static UnauthorizedValueException forUnknownValue(String field) { - return new UnauthorizedValueException(new RuntimeException(defaultMessage(field) + " (unknown)")); - } - - public static UnauthorizedValueException forTooShortValue(String field) { - return new UnauthorizedValueException(new RuntimeException(defaultMessage(field) + " (too short)")); - } - - public static UnauthorizedValueException forUnexpectedValue(String field, Object input, Object expectedValue) { - return new UnauthorizedValueException( - new RuntimeException(defaultMessage(field) + " (expected : \"" + expectedValue + "\", found : \"" + input.toString() + "\")") - ); - } -} diff --git a/src/test/java/tech/jhipster/lite/shared/error/domain/UnauthorizedValueExceptionTest.java b/src/test/java/tech/jhipster/lite/shared/error/domain/UnauthorizedValueExceptionTest.java deleted file mode 100644 index cf41b9743f1..00000000000 --- a/src/test/java/tech/jhipster/lite/shared/error/domain/UnauthorizedValueExceptionTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package tech.jhipster.lite.shared.error.domain; - -import static org.assertj.core.api.Assertions.*; - -import org.junit.jupiter.api.Test; -import tech.jhipster.lite.UnitTest; - -@UnitTest -class UnauthorizedValueExceptionTest { - - public static final String FIELD = "field"; - - @Test - void shouldGetExceptionInformation() { - UnauthorizedValueException exception = new UnauthorizedValueException(FIELD); - assertThat(exception.getMessage()).isEqualTo("The field \"field\" was given an unauthorized value"); - } - - @Test - void shouldGetExceptionForBlankValue() { - UnauthorizedValueException exception = UnauthorizedValueException.forNegativeValue(FIELD); - - assertThat(exception.getMessage()).isEqualTo("The field \"field\" was given an unauthorized value (negative)"); - } - - @Test - void shouldGetExceptionForInconsistentValue() { - UnauthorizedValueException exception = UnauthorizedValueException.forInconsistentValue(FIELD, 132); - - assertThat(exception.getMessage()).isEqualTo("The field \"field\" was given an unauthorized value (inconsistent : 132)"); - } - - @Test - void shouldGetExceptionForInconsistentValues() { - UnauthorizedValueException exception = UnauthorizedValueException.forInconsistentValues("field1", 1, "field2", 2); - - assertThat(exception.getMessage()) - .isEqualTo("The field \"field2\" was given an unauthorized value (2 which is inconsistent with \"field1\" : 1)"); - } - - @Test - void shouldGetExceptionForUnknownValue() { - UnauthorizedValueException exception = UnauthorizedValueException.forUnknownValue(FIELD); - assertThat(exception.getMessage()).isEqualTo("The field \"field\" was given an unauthorized value (unknown)"); - } - - @Test - void shouldGetExceptionForUnequalValue() { - UnauthorizedValueException exception = UnauthorizedValueException.forUnequalValues("field1", "field2", 2, 3); - assertThat(exception.getMessage()) - .isEqualTo("The field \"field2\" was given an unauthorized value (3 not equal with field \"field1\" : 2)"); - } - - @Test - void shouldGetExceptionForUnexpectedType() { - UnauthorizedValueException exception = UnauthorizedValueException.forUnexpectedType(FIELD); - assertThat(exception.getMessage()).isEqualTo("The field \"field\" was given an unauthorized value (unexpected type)"); - } - - @Test - void shouldGetExceptionForTooShortValue() { - UnauthorizedValueException exception = UnauthorizedValueException.forTooShortValue(FIELD); - assertThat(exception.getMessage()).isEqualTo("The field \"field\" was given an unauthorized value (too short)"); - } - - @Test - void shouldGetExceptionForUnexpectedValue() { - UnauthorizedValueException exception = UnauthorizedValueException.forUnexpectedValue(FIELD, "Simpson", "Soprano"); - assertThat(exception.getMessage()) - .isEqualTo("The field \"field\" was given an unauthorized value (expected : \"Soprano\", found : \"Simpson\")"); - } -}