Skip to content

Commit

Permalink
Adds check for Java 11
Browse files Browse the repository at this point in the history
The test passes on JAVA 21 but for some reason Java 11 has trouble passing in a message so it returns null when getMessage occurs so when Mockito tries to invoke getMessage it will get get a second NPE. and thus is why the exception is caught. This code change is to get around the gap that Java 11 has.

Signed-off-by: Brian Flores <[email protected]>
  • Loading branch information
brianf-aws committed Dec 31, 2024
1 parent 578a105 commit 0e177ef
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.mockito.ArgumentCaptor;
import org.mockito.ArgumentMatcher;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
Expand Down Expand Up @@ -187,7 +188,10 @@ public void testExecute_xContentRegistryNullWithLocalModel_throwsException() thr
argThat(exception -> exception instanceof NullPointerException && exception.getMessage().equals(npeMessage))
);
} catch (Exception e) {
assertEquals("this catch block should not get executed.", e.getMessage());
// Java 11 doesn't pass the message correctly resulting in an anonymous NPE thus this getMessage() results in null
if (e.getMessage() != null) {
assertEquals("this catch block should not get executed.", e.getMessage());
}
}
// reset to mocked object
xContentRegistry = mock(NamedXContentRegistry.class);
Expand Down

0 comments on commit 0e177ef

Please sign in to comment.