Skip to content

Commit 25d4d23

Browse files
Nylleakutschera
authored andcommitted
Use better exception for error-case
Refs: #91
1 parent 8a56fa7 commit 25d4d23

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/main/java/com/github/nylle/javafixture/annotations/testcases/ReflectedTestCase.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.github.nylle.javafixture.annotations.testcases;
22

3-
import com.github.nylle.javafixture.SpecimenException;
4-
53
import java.lang.reflect.InvocationTargetException;
64
import java.lang.reflect.Method;
75
import java.util.ArrayList;
@@ -50,7 +48,7 @@ private <T> void validate(Class<T> type, int i) {
5048
.collect(toList());
5149

5250
if(isInvalid(type, nonDefaultValues)) {
53-
throw new SpecimenException(String.format("Duplicate customisation found for argument at position %d, wanted: %s, found: %s",
51+
throw new TestCaseException(String.format("Duplicate customisation found for argument at position %d, wanted: %s, found: %s",
5452
i + 1,
5553
type.getName(),
5654
nonDefaultValues.stream().map(x -> x.getClass().getName()).collect(joining(", "))));

src/main/java/com/github/nylle/javafixture/annotations/testcases/TestCaseException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
public class TestCaseException extends RuntimeException {
44

5+
public TestCaseException(final String message) {
6+
super(message);
7+
}
8+
59
public TestCaseException(final String message, final Throwable cause) {
610
super(message, cause);
711
}

src/test/java/com/github/nylle/javafixture/annotations/testcases/ReflectedTestCaseTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.nylle.javafixture.annotations.testcases;
22

3-
import com.github.nylle.javafixture.SpecimenException;
43
import com.github.nylle.javafixture.testobjects.TestObject;
54
import org.junit.jupiter.api.Test;
65

@@ -22,52 +21,52 @@ void getTestCaseValueFor_ThrowsIfTwoDifferentValuesAreCustomized() {
2221

2322
var sut = new ReflectedTestCase(testCaseWithDuplicateCustomizationsAt_1_2_3_4_6);
2423

25-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(String.class, 0))
24+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(String.class, 0))
2625
.withMessageContaining("Duplicate customisation found for argument at position 1, wanted: java.lang.String, found: ")
2726
.withMessageContaining("java.lang.Boolean")
2827
.withMessageContaining("java.lang.String");
2928

30-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(Boolean.class, 0))
29+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(Boolean.class, 0))
3130
.withMessageContaining("Duplicate customisation found for argument at position 1, wanted: java.lang.Boolean, found: ")
3231
.withMessageContaining("java.lang.Boolean")
3332
.withMessageContaining("java.lang.String");
3433

35-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(Float.class, 1))
34+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(Float.class, 1))
3635
.withMessageContaining("Duplicate customisation found for argument at position 2, wanted: java.lang.Float, found: ")
3736
.withMessageContaining("java.lang.Float")
3837
.withMessageContaining("java.lang.Long");
3938

40-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(Long.class, 1))
39+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(Long.class, 1))
4140
.withMessageContaining("Duplicate customisation found for argument at position 2, wanted: java.lang.Long, found: ")
4241
.withMessageContaining("java.lang.Float")
4342
.withMessageContaining("java.lang.Long");
4443

45-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(TestObject.class.getClass(), 2))
44+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(TestObject.class.getClass(), 2))
4645
.withMessageContaining("Duplicate customisation found for argument at position 3, wanted: java.lang.Class, found: ")
4746
.withMessageContaining("java.lang.Class")
4847
.withMessageContaining("java.lang.Integer");
4948

50-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(Integer.class, 2))
49+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(Integer.class, 2))
5150
.withMessageContaining("Duplicate customisation found for argument at position 3, wanted: java.lang.Integer, found: ")
5251
.withMessageContaining("java.lang.Class")
5352
.withMessageContaining("java.lang.Integer");
5453

55-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(Short.class, 3))
54+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(Short.class, 3))
5655
.withMessageContaining("Duplicate customisation found for argument at position 4, wanted: java.lang.Short, found: ")
5756
.withMessageContaining("java.lang.Short")
5857
.withMessageContaining("java.lang.Character");
5958

60-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(Character.class, 3))
59+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(Character.class, 3))
6160
.withMessageContaining("Duplicate customisation found for argument at position 4, wanted: java.lang.Character, found: ")
6261
.withMessageContaining("java.lang.Short")
6362
.withMessageContaining("java.lang.Character");
6463

65-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(Byte.class, 5))
64+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(Byte.class, 5))
6665
.withMessageContaining("Duplicate customisation found for argument at position 6, wanted: java.lang.Byte, found: ")
6766
.withMessageContaining("java.lang.Byte")
6867
.withMessageContaining("java.lang.Double");
6968

70-
assertThatExceptionOfType(SpecimenException.class).isThrownBy(() -> sut.getTestCaseValueFor(Double.class, 5))
69+
assertThatExceptionOfType(TestCaseException.class).isThrownBy(() -> sut.getTestCaseValueFor(Double.class, 5))
7170
.withMessageContaining("Duplicate customisation found for argument at position 6, wanted: java.lang.Double, found: ")
7271
.withMessageContaining("java.lang.Byte")
7372
.withMessageContaining("java.lang.Double");

0 commit comments

Comments
 (0)