Permalink
Browse files

Tweaked CompletionHandler to use a stateless enum variant

  • Loading branch information...
jbrisbin committed Aug 18, 2011
1 parent 3e683e1 commit 3a06e62cadcf92cf314e896e6403e17546e3bd02
Showing with 7 additions and 5 deletions.
  1. +7 −5 async-api-tests/src/test/java/org/springframework/async/PromiseTests.java
@@ -12,9 +12,11 @@
@SuppressWarnings({"unchecked"})
public class PromiseTests {
- private final Logger log = LoggerFactory.getLogger(getClass());
+ private static final Logger log = LoggerFactory.getLogger(PromiseTests.class);
+
+ private static enum Handler implements CompletionHandler<String, CountDownLatch> {
+ INSTANCE;
- private CompletionHandler<String, CountDownLatch> handler = new CompletionHandler<String, CountDownLatch>() {
@Override public void completed(String result, CountDownLatch latch) {
log.info("Got result: " + result + " with attachment: " + latch);
latch.countDown();
@@ -24,15 +26,15 @@
log.error(t.getMessage(), t);
latch.countDown();
}
+ }
- };
@Test
public void testPromiseCompletionHandler() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
LongRunningAction action = new LongRunningAction();
- action.executeLongRunningAction(latch).complete(handler);
+ action.executeLongRunningAction(latch).complete(Handler.INSTANCE);
latch.await();
}
@@ -42,7 +44,7 @@ public void testPromiseFailure() throws InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
LongRunningAction action = new LongRunningAction();
- action.executeFailedAction(latch).complete(handler);
+ action.executeFailedAction(latch).complete(Handler.INSTANCE);
latch.await();
}

0 comments on commit 3a06e62

Please sign in to comment.