Home | History | Annotate | Download | only in reflection
      1 /*
      2  * Copyright (c) 2007 Mockito contributors
      3  * This program is made available under the terms of the MIT License.
      4  */
      5 
      6 package org.mockito.internal.util.reflection;
      7 
      8 import org.junit.Test;
      9 
     10 import java.lang.reflect.Field;
     11 import java.util.Observable;
     12 
     13 import static org.mockitoutil.VmArgAssumptions.assumeVmArgPresent;
     14 
     15 public class AccessibilityChangerTest {
     16 
     17     @SuppressWarnings("unused")
     18     private Observable whatever;
     19 
     20     @Test
     21     public void should_enable_and_safely_disable() throws Exception {
     22         AccessibilityChanger changer = new AccessibilityChanger();
     23         changer.enableAccess(field("whatever"));
     24         changer.safelyDisableAccess(field("whatever"));
     25     }
     26 
     27     @Test(expected = java.lang.AssertionError.class)
     28     public void safelyDisableAccess_should_fail_when_enableAccess_not_called() throws Exception {
     29         assumeVmArgPresent("-ea");
     30         new AccessibilityChanger().safelyDisableAccess(field("whatever"));
     31     }
     32 
     33 
     34     private Field field(String fieldName) throws NoSuchFieldException {
     35         return this.getClass().getDeclaredField(fieldName);
     36     }
     37 
     38 }
     39