### Question:
GroovySandboxValueFilter extends GroovyValueFilter { @Override public Object filter(final Object target) { if (target == null) { return null; } if (target instanceof Closure) { return target; } Class<?> clazz = target instanceof Class ? (Class<?>) target : target.getClass(); if (clazz.isArray()) { clazz = clazz.getComponentType(); } final String className = clazz.getName(); if (classShutter.visibleToScripts(className)) { return target; } else { throw new SecurityException(String.format(ERROR_MESSAGE, className)); } } GroovySandboxValueFilter(final ClassShutter classShutter); @Override Object filter(final Object target); @Override Object onGetProperty(Invoker invoker, Object receiver, String property); @Override Object onSetProperty(Invoker invoker, Object receiver, String property, Object value); @Override Object onMethodCall(Invoker invoker, Object receiver, String method, Object... args);  }### Answer:
@Test public void shouldAllowNullObjects() { Object result = testFilter.filter(null); assertThat(result).isNull(); }
@Test public void shouldDelegateInstanceCallsToClassShutter() { Object target = "a test object"; given(mockClassShutter.visibleToScripts(target.getClass().getName())).willReturn(true); Object result = testFilter.filter(target); assertThat(result).isSameAs(target); }
@Test public void shouldDelegateStaticCallsToClassShutter() { Class<?> target = String.class; given(mockClassShutter.visibleToScripts(target.getName())).willReturn(true); Object result = testFilter.filter(target); assertThat(result).isSameAs(target); }
@Test(expectedExceptions = SecurityException.class) public void shouldRejectObjectsThatDoNoMatchShutter() { Object target = "a test object"; given(mockClassShutter.visibleToScripts(target.getClass().getName())).willReturn(false); testFilter.filter(target); }