1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.apache.hc.core5.testing.framework;
29
30 import java.io.IOException;
31
32 import org.apache.hc.core5.http.ClassicHttpRequest;
33 import org.apache.hc.core5.http.ClassicHttpResponse;
34 import org.apache.hc.core5.http.HttpException;
35 import org.apache.hc.core5.http.protocol.HttpContext;
36 import org.junit.jupiter.api.Assertions;
37 import org.junit.jupiter.api.Test;
38
39 public class TestTestingFrameworkRequestHandler {
40 @Test
41 public void assertNothingThrown() throws Exception {
42 final TestingFrameworkRequestHandler handler = new TestingFrameworkRequestHandler() {
43
44 @Override
45 public void handle(final ClassicHttpRequest request, final ClassicHttpResponse response, final HttpContext context)
46 throws HttpException, IOException {
47 }
48 };
49
50 handler.assertNothingThrown();
51 }
52
53 @Test
54 public void assertNothingThrownThrows() throws Exception {
55 final String errorMessage = "thrown intentionally";
56
57 final TestingFrameworkRequestHandler handler = new TestingFrameworkRequestHandler() {
58
59 @Override
60 public void handle(final ClassicHttpRequest request, final ClassicHttpResponse response, final HttpContext context)
61 throws HttpException, IOException {
62 thrown = new TestingFrameworkException(errorMessage);
63 }
64 };
65
66 handler.handle(null, null, null);
67 final TestingFrameworkException exception = Assertions.assertThrows(TestingFrameworkException.class,
68 () -> handler.assertNothingThrown());
69 Assertions.assertEquals(errorMessage, exception.getMessage(), "Unexpected message");
70
71 handler.assertNothingThrown();
72 }
73
74 }