|
20 | 20 | import org.junit.jupiter.api.function.Executable; |
21 | 21 |
|
22 | 22 | import static io.netty.handler.codec.http.HttpResponseStatus.parseLine; |
23 | | -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; |
24 | 24 | import static org.junit.jupiter.api.Assertions.assertEquals; |
25 | 25 | import static org.junit.jupiter.api.Assertions.assertNotSame; |
26 | 26 | import static org.junit.jupiter.api.Assertions.assertSame; |
@@ -121,24 +121,42 @@ public void constructorMustRejectControlCharactersAndDelInReasonPhrase() { |
121 | 121 | // HTAB is allowed by the RFC 9110 reason-phrase grammar. |
122 | 122 | continue; |
123 | 123 | } |
124 | | - String phrase = "OK" + c + "Injected"; |
125 | | - assertThatThrownBy(() -> new HttpResponseStatus(200, phrase)) |
126 | | - .isInstanceOf(IllegalArgumentException.class) |
127 | | - .hasMessageContaining("invalid character"); |
| 124 | + assertConstructorRejects("OK" + c + "Injected"); |
128 | 125 | } |
129 | | - assertThatThrownBy(() -> new HttpResponseStatus(200, "OK\u007FInjected")) |
130 | | - .isInstanceOf(IllegalArgumentException.class) |
131 | | - .hasMessageContaining("invalid character"); |
| 126 | + assertConstructorRejects("OK\u007FInjected"); |
| 127 | + } |
| 128 | + |
| 129 | + private static void assertConstructorRejects(final String phrase) { |
| 130 | + IllegalArgumentException e = assertThrows(IllegalArgumentException.class, new Executable() { |
| 131 | + @Override |
| 132 | + public void execute() { |
| 133 | + new HttpResponseStatus(200, phrase); |
| 134 | + } |
| 135 | + }); |
| 136 | + assertThat(e).hasMessageContaining("invalid character"); |
132 | 137 | } |
133 | 138 |
|
134 | 139 | @Test |
135 | 140 | public void parseLineMustRejectControlCharactersAndDelInReasonPhrase() { |
136 | | - assertThrows(IllegalArgumentException.class, () -> parseLine("200 OK\u0000Injected")); |
137 | | - assertThrows(IllegalArgumentException.class, () -> parseLine("200 OK\u000BInjected")); |
138 | | - assertThrows(IllegalArgumentException.class, () -> parseLine("200 OK\fInjected")); |
139 | | - assertThrows(IllegalArgumentException.class, () -> parseLine("200 OK\u007FInjected")); |
140 | | - assertThrows(IllegalArgumentException.class, () -> parseLine(new AsciiString("200 OK\u0000Injected"))); |
141 | | - assertThrows(IllegalArgumentException.class, () -> parseLine(new AsciiString("200 OK\u007FInjected"))); |
| 141 | + assertParseLineRejects("200 OK\u0000Injected"); |
| 142 | + assertParseLineRejects("200 OK\u000BInjected"); |
| 143 | + assertParseLineRejects("200 OK\fInjected"); |
| 144 | + assertParseLineRejects("200 OK\u007FInjected"); |
| 145 | + } |
| 146 | + |
| 147 | + private static void assertParseLineRejects(final String line) { |
| 148 | + assertThrows(IllegalArgumentException.class, new Executable() { |
| 149 | + @Override |
| 150 | + public void execute() { |
| 151 | + parseLine(line); |
| 152 | + } |
| 153 | + }); |
| 154 | + assertThrows(IllegalArgumentException.class, new Executable() { |
| 155 | + @Override |
| 156 | + public void execute() { |
| 157 | + parseLine(new AsciiString(line)); |
| 158 | + } |
| 159 | + }); |
142 | 160 | } |
143 | 161 |
|
144 | 162 | @Test |
|