SEC-2682: DelegatingSecurityContextRunnable/Callable delegate toString()

This commit is contained in:
Rob Winch 2014-11-20 11:51:05 -06:00
parent 05882b5f24
commit 3089f1603e
4 changed files with 26 additions and 0 deletions

View File

@ -64,6 +64,10 @@ public final class DelegatingSecurityContextCallable<V> implements Callable<V> {
} }
} }
public String toString() {
return delegate.toString();
}
/** /**
* Creates a {@link DelegatingSecurityContextCallable} and with the given {@link Callable} and * Creates a {@link DelegatingSecurityContextCallable} and with the given {@link Callable} and
* {@link SecurityContext}, but if the securityContext is null will defaults to the current {@link SecurityContext} * {@link SecurityContext}, but if the securityContext is null will defaults to the current {@link SecurityContext}

View File

@ -61,6 +61,10 @@ public final class DelegatingSecurityContextRunnable implements Runnable {
} }
} }
public String toString() {
return delegate.toString();
}
/** /**
* Factory method for creating a {@link DelegatingSecurityContextRunnable}. * Factory method for creating a {@link DelegatingSecurityContextRunnable}.
* *

View File

@ -126,6 +126,15 @@ public class DelegatingSecurityContextCallableTests {
assertWrapped(callable.call()); assertWrapped(callable.call());
} }
// --- toString
// SEC-2682
@Test
public void toStringDelegates() {
callable = new DelegatingSecurityContextCallable<Object>(delegate, securityContext);
assertThat(callable.toString()).isEqualTo(delegate.toString());
}
private void assertWrapped(Object actualResult) throws Exception { private void assertWrapped(Object actualResult) throws Exception {
assertThat(actualResult).isEqualTo(callableResult); assertThat(actualResult).isEqualTo(callableResult);
verify(delegate).call(); verify(delegate).call();

View File

@ -127,6 +127,15 @@ public class DelegatingSecurityContextRunnableTests {
assertWrapped(); assertWrapped();
} }
// --- toString
// SEC-2682
@Test
public void toStringDelegates() {
runnable = new DelegatingSecurityContextRunnable(delegate, securityContext);
assertThat(runnable.toString()).isEqualTo(delegate.toString());
}
private void assertWrapped() { private void assertWrapped() {
verify(delegate).run(); verify(delegate).run();
assertThat(SecurityContextHolder.getContext()).isEqualTo(SecurityContextHolder.createEmptyContext()); assertThat(SecurityContextHolder.getContext()).isEqualTo(SecurityContextHolder.createEmptyContext());