修正 InvalidInputExceptionTests 和 ParsingFailureExceptionTests

1.x.x
ZhouXY108 2024-12-26 11:38:24 +08:00
parent 1fde8a9b8a
commit cee24b3d10
2 changed files with 57 additions and 57 deletions

View File

@ -37,7 +37,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS.create();
});
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS, e.getType());
assertSame(InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS, e.getType());
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS.getCode(), e.getCode());
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS.getDefaultMessage(), e.getMessage());
assertNull(e.getCause());
@ -49,7 +49,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS.create(message);
});
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS, e.getType());
assertSame(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS, e.getType());
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
@ -61,7 +61,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw InvalidInputException.Type.PICTURE_CONTAINS_ILLEGAL_INFORMATION.create(message);
});
assertEquals(InvalidInputException.Type.PICTURE_CONTAINS_ILLEGAL_INFORMATION, e.getType());
assertSame(InvalidInputException.Type.PICTURE_CONTAINS_ILLEGAL_INFORMATION, e.getType());
assertEquals(InvalidInputException.Type.PICTURE_CONTAINS_ILLEGAL_INFORMATION.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -76,11 +76,11 @@ public class InvalidInputExceptionTests {
throw InvalidInputException.Type.INFRINGE_COPYRIGHT.create(nfe);
});
assertEquals(InvalidInputException.Type.INFRINGE_COPYRIGHT, e.getType());
assertSame(InvalidInputException.Type.INFRINGE_COPYRIGHT, e.getType());
assertEquals(InvalidInputException.Type.INFRINGE_COPYRIGHT.getCode(), e.getCode());
log.info("{}", e.getMessage());
assertEquals(nfe.toString(), e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
});
}
@ -91,7 +91,7 @@ public class InvalidInputExceptionTests {
throw InvalidInputException.Type.DEFAULT.create(nfe);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -105,10 +105,10 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS.create(message, nfe);
});
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS, e.getType());
assertSame(InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS, e.getType());
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_AND_MALICIOUS_LINKS.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
}
@Test
@ -119,10 +119,10 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS.create(message, nfe);
});
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS, e.getType());
assertSame(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS, e.getType());
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS.getCode(), e.getCode());
assertNull(e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
}
@Test
@ -133,7 +133,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS.create(message, npe);
});
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS, e.getType());
assertSame(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS, e.getType());
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
@ -147,7 +147,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS.create(message, nfe);
});
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS, e.getType());
assertSame(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS, e.getType());
assertEquals(InvalidInputException.Type.CONTAINS_ILLEGAL_WORDS.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -166,7 +166,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw new InvalidInputException();
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertEquals(InvalidInputException.Type.DEFAULT.getDefaultMessage(), e.getMessage());
assertNull(e.getCause());
@ -178,7 +178,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw new InvalidInputException(message);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
@ -190,7 +190,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw new InvalidInputException(message);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -205,11 +205,11 @@ public class InvalidInputExceptionTests {
throw new InvalidInputException(nfe);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
log.info("{}", e.getMessage());
assertEquals(nfe.toString(), e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
});
}
@ -220,7 +220,7 @@ public class InvalidInputExceptionTests {
throw new InvalidInputException(nfe);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -234,10 +234,10 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw new InvalidInputException(message, nfe);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
}
@Test
@ -248,10 +248,10 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw new InvalidInputException(message, nfe);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertNull(e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
}
@Test
@ -262,7 +262,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw new InvalidInputException(message, npe);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
@ -276,7 +276,7 @@ public class InvalidInputExceptionTests {
InvalidInputException e = assertThrows(InvalidInputException.class, () -> {
throw new InvalidInputException(message, nfe);
});
assertEquals(InvalidInputException.Type.DEFAULT, e.getType());
assertSame(InvalidInputException.Type.DEFAULT, e.getType());
assertEquals(InvalidInputException.Type.DEFAULT.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());

View File

@ -40,7 +40,7 @@ public class ParsingFailureExceptionTests {
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.DATE_TIME_PARSING_FAILURE.create();
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getDefaultMessage(), e.getMessage());
assertNull(e.getCause());
@ -52,7 +52,7 @@ public class ParsingFailureExceptionTests {
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.JSON_PARSING_FAILURE.create(message);
});
assertEquals(ParsingFailureException.Type.JSON_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.Type.JSON_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.Type.JSON_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
@ -64,7 +64,7 @@ public class ParsingFailureExceptionTests {
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.XML_PARSING_FAILURE.create(message);
});
assertEquals(ParsingFailureException.XML_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.XML_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.XML_PARSING_FAILURE.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -79,11 +79,11 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.NUMBER_PARSING_FAILURE.create(nfe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
log.info("{}", e.getMessage());
assertEquals(nfe.toString(), e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
});
}
@ -94,7 +94,7 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.NUMBER_PARSING_FAILURE.create(nfe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -108,10 +108,10 @@ public class ParsingFailureExceptionTests {
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.NUMBER_PARSING_FAILURE.create(message, nfe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
}
@Test
@ -122,10 +122,10 @@ public class ParsingFailureExceptionTests {
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.DATE_TIME_PARSING_FAILURE.create(message, nfe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertNull(e.getMessage());
assertEquals(nfe, e.getCause());
assertSame(nfe, e.getCause());
}
@Test
@ -136,7 +136,7 @@ public class ParsingFailureExceptionTests {
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.DATE_TIME_PARSING_FAILURE.create(message, npe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
@ -150,7 +150,7 @@ public class ParsingFailureExceptionTests {
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.DATE_TIME_PARSING_FAILURE.create(message, nfe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -174,10 +174,10 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(dtpe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(dtpe.getMessage(), e.getMessage());
assertEquals(dtpe, e.getCause());
assertSame(dtpe, e.getCause());
}
@Test
@ -188,7 +188,7 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(dtpe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getDefaultMessage(), e.getMessage());
assertNull(e.getCause());
@ -205,10 +205,10 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(message, dtpe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertEquals(dtpe, e.getCause());
assertSame(dtpe, e.getCause());
}
@Test
@ -222,10 +222,10 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(message, dtpe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertNull(e.getMessage());
assertEquals(dtpe, e.getCause());
assertSame(dtpe, e.getCause());
}
@Test
@ -237,7 +237,7 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(message, dtpe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
@ -252,7 +252,7 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(message, dtpe);
});
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.DATE_TIME_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.DATE_TIME_PARSING_FAILURE.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());
@ -269,17 +269,17 @@ public class ParsingFailureExceptionTests {
@Test
void test_createByOf_withNumberFormatException() {
NumberFormatException dtpe = assertThrows(NumberFormatException.class, () -> {
LocalDateTime.parse("abcd", DateTimeFormatter.ISO_DATE_TIME);
Integer.parseInt("abcd");
});
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.of(dtpe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(dtpe.getMessage(), e.getMessage());
assertEquals(dtpe, e.getCause());
assertSame(dtpe, e.getCause());
}
@Test
@ -290,7 +290,7 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(dtpe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getDefaultMessage(), e.getMessage());
assertNull(e.getCause());
@ -300,34 +300,34 @@ public class ParsingFailureExceptionTests {
void test_createByOf_withNumberFormatExceptionAndMessage() {
final String message = "test_createByOf_withNumberFormatExceptionAndMessage";
NumberFormatException dtpe = assertThrows(NumberFormatException.class, () -> {
LocalDateTime.parse("abcd", DateTimeFormatter.ISO_DATE_TIME);
Integer.parseInt("abcd");
});
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.of(message, dtpe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertEquals(dtpe, e.getCause());
assertSame(dtpe, e.getCause());
}
@Test
void test_createByOf_withNumberFormatExceptionAndNullMessage() {
final String message = null;
NumberFormatException dtpe = assertThrows(NumberFormatException.class, () -> {
LocalDateTime.parse("abcd", DateTimeFormatter.ISO_DATE_TIME);
Integer.parseInt("abcd");
});
ParsingFailureException e = assertThrows(ParsingFailureException.class, () -> {
throw ParsingFailureException.of(message, dtpe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
assertNull(e.getMessage());
assertEquals(dtpe, e.getCause());
assertSame(dtpe, e.getCause());
}
@Test
@ -339,7 +339,7 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(message, dtpe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
assertEquals(message, e.getMessage());
assertNull(e.getCause());
@ -354,7 +354,7 @@ public class ParsingFailureExceptionTests {
throw ParsingFailureException.of(message, dtpe);
});
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertSame(ParsingFailureException.NUMBER_PARSING_FAILURE, e.getType());
assertEquals(ParsingFailureException.NUMBER_PARSING_FAILURE.getCode(), e.getCode());
assertNull(e.getMessage());
assertNull(e.getCause());