Added new test case for IllegalArgumentException

This commit is contained in:
Umang Budhwar 2020-06-19 22:20:57 +05:30
parent f726917306
commit efa72998e5
2 changed files with 13 additions and 2 deletions

View File

@ -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

View File

@ -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 {