@Test public void testSetInstance$securityManager$exceptionPath() throws Exception { class CustomSecurityManager extends SecurityManager { @Override public void checkPermission(Permission permission) { if(permission instanceof ReflectPermission) { ReflectPermission rp=(ReflectPermission)permission; if(rp.getName().equals("suppressAccessChecks")) { throw new SecurityException("FAILURE"); } } } }; final SecurityManager manager=new CustomSecurityManager(); new MockUp<RuntimeDelegate>() { @Mock public SecurityManager getSecurityManager() { return manager; } }; try { RuntimeDelegate.setInstance(new CustomRuntimeDelegate()); fail("Should not be able to set instance if reflection is not allowed"); } catch (SecurityException e) { assertThat(e.getMessage(),equalTo("FAILURE")); } }
public static void setInstance(final RuntimeDelegate delegate) { SecurityManager security = getSecurityManager(); if (security != null) { security.checkPermission(SUPPRESS_ACCESS_CHECKS_PERMISSION); } synchronized(RuntimeDelegate.CACHED_DELEGATE) { RuntimeDelegate.CACHED_DELEGATE.set(delegate); } }
RuntimeDelegate { public static void setInstance(final RuntimeDelegate delegate) { SecurityManager security = getSecurityManager(); if (security != null) { security.checkPermission(SUPPRESS_ACCESS_CHECKS_PERMISSION); } synchronized(RuntimeDelegate.CACHED_DELEGATE) { RuntimeDelegate.CACHED_DELEGATE.set(delegate); } } }
RuntimeDelegate { public static void setInstance(final RuntimeDelegate delegate) { SecurityManager security = getSecurityManager(); if (security != null) { security.checkPermission(SUPPRESS_ACCESS_CHECKS_PERMISSION); } synchronized(RuntimeDelegate.CACHED_DELEGATE) { RuntimeDelegate.CACHED_DELEGATE.set(delegate); } } protected  RuntimeDelegate(); }
RuntimeDelegate { public static void setInstance(final RuntimeDelegate delegate) { SecurityManager security = getSecurityManager(); if (security != null) { security.checkPermission(SUPPRESS_ACCESS_CHECKS_PERMISSION); } synchronized(RuntimeDelegate.CACHED_DELEGATE) { RuntimeDelegate.CACHED_DELEGATE.set(delegate); } } protected  RuntimeDelegate(); static RuntimeDelegate getInstance(); static void setInstance(final RuntimeDelegate delegate); abstract boolean isOffline(); abstract WriteSession createSession(); abstract ResourceSnapshotResolver createResourceResolver(URI canonicalBase, ReadSession session); abstract void registerShutdownListener(ShutdownListener listener); }
RuntimeDelegate { public static void setInstance(final RuntimeDelegate delegate) { SecurityManager security = getSecurityManager(); if (security != null) { security.checkPermission(SUPPRESS_ACCESS_CHECKS_PERMISSION); } synchronized(RuntimeDelegate.CACHED_DELEGATE) { RuntimeDelegate.CACHED_DELEGATE.set(delegate); } } protected  RuntimeDelegate(); static RuntimeDelegate getInstance(); static void setInstance(final RuntimeDelegate delegate); abstract boolean isOffline(); abstract WriteSession createSession(); abstract ResourceSnapshotResolver createResourceResolver(URI canonicalBase, ReadSession session); abstract void registerShutdownListener(ShutdownListener listener); static final String APPLICATION_ENGINE_SPI_FINDER; static final String APPLICATION_ENGINE_SPI_CFG; static final String APPLICATION_ENGINE_SPI_PROPERTY; }