forked from pierront/mylibrary-template
suite
This commit is contained in:
+46
@@ -0,0 +1,46 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.avis.exception;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class AvisNotFoundExceptionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Exception message should contain the UUID provided")
|
||||||
|
void testExceptionMessageContainsUUID() {
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
|
AvisNotFoundException exception = new AvisNotFoundException(uuid);
|
||||||
|
|
||||||
|
String expectedMessage = String.format("The avis with id %s does not exist", uuid);
|
||||||
|
assertEquals(expectedMessage, exception.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Exception should use the correct constant message format")
|
||||||
|
void testExceptionUsesConstantMessageFormat() {
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
|
AvisNotFoundException exception = new AvisNotFoundException(uuid);
|
||||||
|
|
||||||
|
assertEquals("The avis with id {0} does not exist",
|
||||||
|
AvisNotFoundException.THE_AVIS_WITH_ID_DOES_NOT_EXIST_MESSAGE);
|
||||||
|
assertTrue(exception.getMessage().contains(uuid.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Exception should be properly thrown and caught")
|
||||||
|
void testExceptionCanBeThrownAndCaught() {
|
||||||
|
UUID uuid = UUID.randomUUID();
|
||||||
|
|
||||||
|
try {
|
||||||
|
throw new AvisNotFoundException(uuid);
|
||||||
|
} catch (AvisNotFoundException e) {
|
||||||
|
assertTrue(e.getMessage().contains(uuid.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user