1313import org .junit .Rule ;
1414import org .junit .Test ;
1515import org .junit .rules .ExpectedException ;
16- import org .junit .runner .RunWith ;
17- import org .junit .runners .JUnit4 ;
1816import org .mockito .InOrder ;
1917import org .mockito .InjectMocks ;
2018import org .mockito .Mock ;
2523import javax .servlet .http .HttpServletResponse ;
2624import java .net .MalformedURLException ;
2725import java .util .Date ;
26+ import java .util .concurrent .TimeUnit ;
2827
29- import static org .hamcrest .CoreMatchers .*;
30- import static org .hamcrest .MatcherAssert .assertThat ;
31- import static org .hamcrest .core .Is .is ;
32- import static org .hamcrest .core .StringContains .containsString ;
28+ import static org .hamcrest .Matchers .*;
29+ import static org .junit .Assert .*;
3330import static org .mockito .Mockito .*;
3431
35- @ RunWith (JUnit4 .class )
3632public class HttpServerHandlerTest {
3733
3834 @ Rule public final ExpectedException thrown = ExpectedException .none ();
@@ -152,7 +148,7 @@ public void requestTelemetryFieldsAreSetWhenHandleStartIsInvoked() throws Malfor
152148 }
153149
154150 @ Test
155- public void timeStatusCodeAreSetWhenHandleEndIsInvoked () throws MalformedURLException {
151+ public void timeStatusCodeAreSetWhenHandleEndIsInvoked () throws Exception {
156152 RequestTelemetryContext rtc = httpServerHandler .handleStart (request , response );
157153 RequestTelemetry rt = rtc .getHttpRequestTelemetry ();
158154 assertThat (rt .getId (), is (CoreMatchers .<String >notNullValue ()));
@@ -161,7 +157,7 @@ public void timeStatusCodeAreSetWhenHandleEndIsInvoked() throws MalformedURLExce
161157 assertThat (rt .getUrl ().toString (), equalTo (url ));
162158 assertThat (rt .getContext ().getUser ().getUserAgent (), equalTo ("User-Agent" ));
163159 assertThat (rt .getTimestamp (), is (CoreMatchers .<Date >notNullValue ()));
164-
160+ TimeUnit . MILLISECONDS . sleep ( 100 ); // pause so duration is nonzero
165161 httpServerHandler .handleEnd (request , response , rtc );
166162 // ensure same request telemetry is modified (picked from TLS)
167163 assertThat (rt .getDuration ().getTotalMilliseconds (), is (not (0L )));
0 commit comments