From a951d80b419ef562f688a1afaae492098eb3e66e Mon Sep 17 00:00:00 2001 From: Umang Budhwar Date: Tue, 23 Jun 2020 21:48:01 +0530 Subject: [PATCH] Removed test cases for getting private methods --- .../AccessPrivateMethodsUnitTest.java | 81 ------------------- 1 file changed, 81 deletions(-) delete mode 100644 core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/access/privatefields/AccessPrivateMethodsUnitTest.java diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/access/privatefields/AccessPrivateMethodsUnitTest.java b/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/access/privatefields/AccessPrivateMethodsUnitTest.java deleted file mode 100644 index df745897d2..0000000000 --- a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/access/privatefields/AccessPrivateMethodsUnitTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.baeldung.reflection.access.privatefields; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class AccessPrivateMethodsUnitTest { - - @Test - public void whenGetMethod_thenSuccess() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NullPointerException { - Person person = new Person(); - - Method method = person.getClass() - .getDeclaredMethod("greet", String.class); - method.setAccessible(true); - - String greetMessage = (String) method.invoke(person, "Jane"); - - Assertions.assertEquals("Hello Jane", greetMessage); - } - - @Test - public void givenInt_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, 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 { - Person person = new Person(); - - Method method = person.getClass() - .getDeclaredMethod("greet", String.class); - - Assertions.assertThrows(IllegalAccessException.class, () -> method.invoke(person, "Jane")); - } - - @Test - public void whenCallingMethodThrowsException_thenInvocationTargetException() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, NoSuchMethodException, NullPointerException { - Person person = new Person(); - Method method = person.getClass() - .getDeclaredMethod("divideByZeroExample"); - method.setAccessible(true); - Assertions.assertThrows(InvocationTargetException.class, () -> method.invoke(person)); - } - - @Test - public void whenAccessingWrongProperty_thenNoSuchMethodException() throws NoSuchMethodException, NullPointerException { - Person person = new Person(); - - Assertions.assertThrows(NoSuchMethodException.class, () -> person.getClass() - .getDeclaredMethod("greeting", String.class)); - } - - @Test - public void whenAccessingNullMethod_thenNullPointerException() throws NoSuchMethodException, NullPointerException { - Person person = new Person(); - - Assertions.assertThrows(NullPointerException.class, () -> person.getClass() - .getDeclaredMethod(null, String.class)); - } - -}