Skip to content

Commit d425032

Browse files
author
Fabien Zoccola
committed
test(RepertoireCommune): added test for private constructor
1 parent 57b51e5 commit d425032

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/fr/france/RepertoireCommune.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class RepertoireCommune {
3939
private static final Log log = LogFactory.getLog(RepertoireCommune.class);
4040

4141
private RepertoireCommune() {
42-
throw new IllegalStateException("Class utilitaire");
42+
throw new IllegalStateException("Classe utilitaire");
4343
}
4444

4545
private static final List<Commune> COMMUNES = initCommunes();

src/test/java/fr/france/RepertoireCommuneTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fr.france;
22

3+
import java.lang.reflect.InvocationTargetException;
4+
import java.lang.reflect.Constructor;
35
import java.util.Collections;
46
import java.util.List;
57

@@ -9,6 +11,21 @@
911

1012
class RepertoireCommuneTest {
1113

14+
@Test
15+
void test_ConstructionJetteIllegalStateException() throws NoSuchMethodException {
16+
Constructor<RepertoireCommune> constructor = RepertoireCommune.class.getDeclaredConstructor();
17+
constructor.setAccessible(true);
18+
19+
// On vérifie qu'il jette une erreur
20+
assertThrows(InvocationTargetException.class, constructor::newInstance);
21+
try {
22+
constructor.newInstance();
23+
} catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
24+
// On vérifie que la cause est bien une IllegalStateException
25+
assertEquals("java.lang.IllegalStateException: Classe utilitaire", e.getCause().toString());
26+
}
27+
}
28+
1229
@Test
1330
void test_CommunesInitialise() {
1431
assertNotEquals(Collections.emptyList(), RepertoireCommune.getCommunes());

0 commit comments

Comments
 (0)