62 lines
1.7 KiB
Java
62 lines
1.7 KiB
Java
package de.rwu.easydrop.exception;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
class InvalidTransactionExceptionTest {
|
|
|
|
@Test
|
|
void constructor_WithMessage_SetsMessage() {
|
|
// Arrange
|
|
String message = "Invalid Transaction data";
|
|
|
|
// Act
|
|
InvalidTransactionException exception = new InvalidTransactionException(message);
|
|
|
|
// Assert
|
|
assertEquals(message, exception.getMessage());
|
|
}
|
|
|
|
@Test
|
|
void constructor_WithMessageAndCause_SetsMessageAndCause() {
|
|
// Arrange
|
|
String message = "Invalid Transaction data";
|
|
Throwable cause = new IllegalArgumentException("Invalid argument");
|
|
|
|
// Act
|
|
InvalidTransactionException exception = new InvalidTransactionException(message, cause);
|
|
|
|
// Assert
|
|
assertEquals(message, exception.getMessage());
|
|
assertEquals(cause, exception.getCause());
|
|
}
|
|
|
|
@Test
|
|
void constructor_WithNullMessage_SetsNullMessage() {
|
|
// Act
|
|
InvalidTransactionException exception = new InvalidTransactionException(null);
|
|
|
|
// Assert
|
|
assertEquals(null, exception.getMessage());
|
|
}
|
|
|
|
@Test
|
|
void constructor_WithNullCause_SetsNullCause() {
|
|
// Act
|
|
InvalidTransactionException exception = new InvalidTransactionException("Invalid Transaction data", null);
|
|
|
|
// Assert
|
|
assertEquals(null, exception.getCause());
|
|
}
|
|
|
|
@Test
|
|
void throw_InvalidTransactionException() {
|
|
// Act and Assert
|
|
assertThrows(InvalidTransactionException.class, () -> {
|
|
throw new InvalidTransactionException("Invalid Transaction data");
|
|
});
|
|
}
|
|
}
|