Skip to content

Commit

Permalink
use assertThrows instead of catching and asserting exception class in…
Browse files Browse the repository at this point in the history
… TimTransmogrifierTest
  • Loading branch information
mcook42 committed Nov 1, 2024
1 parent d8f3fac commit dc674c8
Showing 1 changed file with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ void testBuildASDNullTimeRethrowsTimeParsingExceptionFromSNMP() {
inputServiceRequest.setSdw(new SDW());
inputServiceRequest.setSnmp(new SNMP());

try {
TimTransmogrifier.buildASD(inputServiceRequest);
fail("Expected TimTransmogrifierException");
} catch (Exception e) {
assertInstanceOf(TimTransmogrifierException.class, e);
}
assertThrows(TimTransmogrifierException.class, () -> TimTransmogrifier.buildASD(inputServiceRequest));
}

@Test
Expand All @@ -133,12 +128,7 @@ void testBuildASDNullTimeRethrowsTimeParsingExceptionFromSDW() {
ServiceRequest inputServiceRequest = new ServiceRequest();
inputServiceRequest.setSdw(new SDW());

try {
TimTransmogrifier.buildASD(inputServiceRequest);
fail("Expected TimTransmogrifierException");
} catch (Exception e) {
assertInstanceOf(TimTransmogrifierException.class, e);
}
assertThrows(TimTransmogrifierException.class, () -> TimTransmogrifier.buildASD(inputServiceRequest));
}

@Test
Expand Down Expand Up @@ -274,12 +264,8 @@ void testConstructorIsPrivate() throws NoSuchMethodException {
Constructor<TimTransmogrifier> constructor = TimTransmogrifier.class.getDeclaredConstructor();
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
constructor.setAccessible(true);
try {
constructor.newInstance();
fail("Expected IllegalAccessException.class");
} catch (Exception e) {
assertEquals(InvocationTargetException.class, e.getClass());
}

assertThrows(InvocationTargetException.class, constructor::newInstance);
}

}

0 comments on commit dc674c8

Please sign in to comment.