Java 类org.springframework.web.context.request.async.DeferredResult.DeferredResultHandler 实例源码

项目:spring4-understanding    文件:DeferredResultTests.java   
@Test
public void onTimeout() throws Exception {
    final StringBuilder sb = new StringBuilder();

    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>(null, "timeout result");
    result.setResultHandler(handler);
    result.onTimeout(new Runnable() {
        @Override
        public void run() {
            sb.append("timeout event");
        }
    });

    result.getInterceptor().handleTimeout(null, null);

    assertEquals("timeout event", sb.toString());
    assertFalse("Should not be able to set result a second time", result.setResult("hello"));
    verify(handler).handleResult("timeout result");
}
项目:class-guard    文件:DeferredResultTests.java   
@Test
public void onTimeout() throws Exception {
    final StringBuilder sb = new StringBuilder();

    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>(null, "timeout result");
    result.setResultHandler(handler);
    result.onTimeout(new Runnable() {
        @Override
        public void run() {
            sb.append("timeout event");
        }
    });

    result.getInterceptor().handleTimeout(null, null);

    assertEquals("timeout event", sb.toString());
    assertFalse("Should not be able to set result a second time", result.setResult("hello"));
    verify(handler).handleResult("timeout result");
}
项目:spring4-understanding    文件:DeferredResultTests.java   
@Test
public void setResult() {
    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>();
    result.setResultHandler(handler);

    assertTrue(result.setResult("hello"));
    verify(handler).handleResult("hello");
}
项目:spring4-understanding    文件:DeferredResultTests.java   
@Test
public void setResultTwice() {
    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>();
    result.setResultHandler(handler);

    assertTrue(result.setResult("hello"));
    assertFalse(result.setResult("hi"));

    verify(handler).handleResult("hello");
}
项目:spring4-understanding    文件:DeferredResultTests.java   
@Test
public void hasResult() {
    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>();
    result.setResultHandler(handler);

    assertFalse(result.hasResult());
    assertNull(result.getResult());

    result.setResult("hello");

    assertEquals("hello", result.getResult());
}
项目:class-guard    文件:DeferredResultTests.java   
@Test
public void setResult() {
    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>();
    result.setResultHandler(handler);

    assertTrue(result.setResult("hello"));
    verify(handler).handleResult("hello");
}
项目:class-guard    文件:DeferredResultTests.java   
@Test
public void setResultTwice() {
    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>();
    result.setResultHandler(handler);

    assertTrue(result.setResult("hello"));
    assertFalse(result.setResult("hi"));

    verify(handler).handleResult("hello");
}
项目:spring4-understanding    文件:DeferredResultTests.java   
@Test
public void isSetOrExpired() {
    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>();
    result.setResultHandler(handler);

    assertFalse(result.isSetOrExpired());

    result.setResult("hello");

    assertTrue(result.isSetOrExpired());

    verify(handler).handleResult("hello");
}
项目:class-guard    文件:DeferredResultTests.java   
@Test
public void isSetOrExpired() {
    DeferredResultHandler handler = mock(DeferredResultHandler.class);

    DeferredResult<String> result = new DeferredResult<String>();
    result.setResultHandler(handler);

    assertFalse(result.isSetOrExpired());

    result.setResult("hello");

    assertTrue(result.isSetOrExpired());

    verify(handler).handleResult("hello");
}