first commit (#11716)
This commit is contained in:
parent
112f771e53
commit
02e4cf9f99
|
@ -2,6 +2,7 @@ package com.baeldung.reflection;
|
|||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -34,6 +35,25 @@ public class OperationsUnitTest {
|
|||
|
||||
assertFalse(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenObject_whenInvokePrivateMethod_thenCheckAccess() throws Exception {
|
||||
Operations operationsInstance = new Operations();
|
||||
Method andPrivatedMethod = Operations.class.getDeclaredMethod("privateAnd", boolean.class, boolean.class);
|
||||
boolean isAccessEnabled = andPrivatedMethod.canAccess(operationsInstance);
|
||||
|
||||
assertFalse(isAccessEnabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenObject_whenInvokePublicMethod_thenEnableAccess() throws Exception {
|
||||
Operations operationsInstance = new Operations();
|
||||
Method andPrivatedMethod = Operations.class.getDeclaredMethod("privateAnd", boolean.class, boolean.class);
|
||||
andPrivatedMethod.trySetAccessible();
|
||||
boolean isAccessEnabled = andPrivatedMethod.canAccess(operationsInstance);
|
||||
|
||||
assertTrue(isAccessEnabled);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenObject_whenInvokePublicMethod_thenCorrect() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue