The task is to cause NoSuchMethodException
exception when calling table.annotationType().getMethod("name")
.
I have following code
@Mock(answer = RETURNS_DEEP_STUBS)
private Table table;
@Test(expectedExceptions = NoSuchMethodException.class)
public void testGetSupportClassesDatabaseThrowException() throws NoSuchMethodException {
String testPackageName = "com.usc.dbd.util.supporttable";
MockitoAnnotations.initMocks(this);
when(table.annotationType().getMethod("name")).thenThrow(NoSuchMethodException.class);
SupportTables.getSupportClasses(testPackageName);
}
The test fails with NullPointerException
on when...
line.
testCompile("org.mockito:mockito-core:2.7.17")
Table
is annotation from javax.persistence
Probably the issue is in mocking Table
interface.
I'm looking for solution how to test such case.
NullPointerException
but I havent been able to narrow down on the dependencies properly.