Added new test case for IllegalArgumentException
This commit is contained in:
parent
f726917306
commit
efa72998e5
|
@ -28,13 +28,13 @@ public class AccessPrivateFieldsUnitTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void givenInt_whenSetStringField_thenIllegalArgumentException() throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException, NullPointerException {
|
||||
public void givenInt_whenGetStringField_thenIllegalArgumentException() throws IllegalAccessException, IllegalArgumentException, NoSuchFieldException, NullPointerException {
|
||||
Person person = new Person();
|
||||
Field fieldName = person.getClass()
|
||||
.getDeclaredField("name");
|
||||
fieldName.setAccessible(true);
|
||||
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> fieldName.setInt(person, 25));
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> fieldName.getInt(person));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -31,6 +31,17 @@ public class AccessPrivateMethodsUnitTest {
|
|||
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> method.invoke(person, 25));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenMultipleParameters_whenInvokeMethod_thenIllegalArgumentException() throws IllegalArgumentException, IllegalAccessException, NoSuchMethodException, NullPointerException {
|
||||
Person person = new Person();
|
||||
|
||||
Method method = person.getClass()
|
||||
.getDeclaredMethod("greet", String.class);
|
||||
method.setAccessible(true);
|
||||
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () -> method.invoke(person, "John", "Jane"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenMethodNotSetAccessible_thenIllegalAccessException() throws IllegalArgumentException, IllegalAccessException, NoSuchMethodException, NullPointerException {
|
||||
|
|
Loading…
Reference in New Issue