Skip to content

Commit

Permalink
qa: Only one method invocation is expected when testing runtime excep…
Browse files Browse the repository at this point in the history
…tions

Refactor the body of try/catch blocks to have only
one invocation possibly throwing a runtime exception.
  • Loading branch information
groldan committed Dec 7, 2023
1 parent 24d6551 commit 4fcd6c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,11 @@ void default_admin_bad_credentials() {
context -> {
assertThat(context).hasNotFailed();
Authentication token = userNamePasswordToken("admin", "badPWD");
EnvironmentAdminAuthenticationProvider envAuthProvider = envAuthProvider(context);

assertThrows(
InternalAuthenticationServiceException.class,
() -> envAuthProvider(context).authenticate(token));
() -> envAuthProvider.authenticate(token));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2687,18 +2687,14 @@ void testLayerGroupRenderingLayers() {
assertEquals(lg2.getStyles(), lg2.styles());

lg2.setMode(LayerGroupInfo.Mode.CONTAINER);
try {
assertEquals(lg2.getLayers(), lg2.layers());
fail("Layer group of Type Container can not be rendered");
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
try {
assertEquals(lg2.getStyles(), lg2.styles());
fail("Layer group of Type Container can not be rendered");
} catch (UnsupportedOperationException e) {
assertTrue(true);
}
assertThrows(
UnsupportedOperationException.class,
lg2::layers,
"Layer group of Type Container can not be rendered");
assertThrows(
UnsupportedOperationException.class,
lg2::styles,
"Layer group of Type Container can not be rendered");

lg2.setMode(LayerGroupInfo.Mode.EO);
assertEquals(1, lg2.layers().size());
Expand All @@ -2718,11 +2714,10 @@ void testRemoveLayerGroupInLayerGroup() throws Exception {
lg2.getStyles().add(data.style1);
catalog.add(lg2);

try {
catalog.remove(data.layerGroup1);
fail("should have failed because lg is in another lg");
} catch (IllegalArgumentException expected) {
}
assertThrows(
IllegalArgumentException.class,
() -> catalog.remove(data.layerGroup1),
"should have failed because lg is in another lg");

// removing the containing layer first should work
catalog.remove(lg2);
Expand Down Expand Up @@ -2871,7 +2866,7 @@ void testGet() {

filter = equal("keywords[3].value", "repeatedKw");
try {
catalog.get(FeatureTypeInfo.class, filter).getName();
catalog.get(FeatureTypeInfo.class, filter);
fail("Expected IAE on multiple results");
} catch (IllegalArgumentException multipleResults) {
assertTrue(true);
Expand Down

0 comments on commit 4fcd6c6

Please sign in to comment.