Skip to content

Commit 328b0a7

Browse files
committed
Testing the private constructor
1 parent c165bec commit 328b0a7

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/test/java/com/thealgorithms/strings/AlternativeStringArrangeTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.thealgorithms.strings;
22

3+
import org.junit.jupiter.api.Test;
34
import org.junit.jupiter.params.ParameterizedTest;
45
import org.junit.jupiter.params.provider.MethodSource;
56

@@ -29,4 +30,17 @@ private static Stream<Object[]> provideTestData() {
2930
void arrangeTest(String input1, String input2, String expected) {
3031
assertEquals(expected, AlternativeStringArrange.arrange(input1, input2));
3132
}
33+
34+
// Testing private constructor to prevent instantiation
35+
@Test
36+
void preventInstantiationTest() {
37+
try {
38+
var constructor = AlternativeStringArrange.class.getDeclaredConstructor();
39+
constructor.setAccessible(true);
40+
constructor.newInstance();
41+
} catch (Exception e) {
42+
assertEquals(IllegalStateException.class, e.getCause().getClass());
43+
assertEquals("Utility class", e.getCause().getMessage());
44+
}
45+
}
3246
}

0 commit comments

Comments
 (0)