|
8 | 8 | import org.junit.jupiter.api.AfterEach; |
9 | 9 | import org.junit.jupiter.api.BeforeEach; |
10 | 10 | import org.junit.jupiter.api.Test; |
| 11 | +import org.junit.jupiter.params.ParameterizedTest; |
| 12 | +import org.junit.jupiter.params.provider.Arguments; |
| 13 | +import org.junit.jupiter.params.provider.MethodSource; |
11 | 14 | import org.slf4j.Logger; |
12 | 15 | import org.slf4j.LoggerFactory; |
13 | 16 |
|
14 | 17 | import java.io.IOException; |
15 | 18 | import java.util.concurrent.ExecutionException; |
16 | 19 | import java.util.concurrent.TimeUnit; |
| 20 | +import java.util.stream.Stream; |
17 | 21 |
|
18 | 22 | import static org.junit.jupiter.api.Assertions.*; |
19 | 23 | import static org.mockito.ArgumentMatchers.anyString; |
@@ -155,6 +159,32 @@ public void fetchSuccess() throws Exception { |
155 | 159 | fetcher.close(); |
156 | 160 | } |
157 | 161 |
|
| 162 | + private static Stream<Arguments> emptyFetchTestData() { |
| 163 | + return Stream.of( |
| 164 | + Arguments.of(""), |
| 165 | + Arguments.of("null") |
| 166 | + ); |
| 167 | + } |
| 168 | + |
| 169 | + @ParameterizedTest |
| 170 | + @MethodSource("emptyFetchTestData") |
| 171 | + public void fetchEmpty(String body) throws Exception { |
| 172 | + this.server.enqueue(new MockResponse().setResponseCode(200).setBody(body)); |
| 173 | + |
| 174 | + ConfigFetcher fetcher = new ConfigFetcher(new OkHttpClient.Builder().build(), |
| 175 | + logger, |
| 176 | + "", |
| 177 | + this.server.url("/").toString(), |
| 178 | + false, |
| 179 | + PollingModes.manualPoll().getPollingIdentifier()); |
| 180 | + |
| 181 | + FetchResponse response = fetcher.fetchAsync(null).get(); |
| 182 | + assertFalse(response.isFetched()); |
| 183 | + assertEquals("Fetching config JSON was successful but the HTTP response content was invalid.", response.error().toString()); |
| 184 | + |
| 185 | + fetcher.close(); |
| 186 | + } |
| 187 | + |
158 | 188 | @Test |
159 | 189 | public void testIntegration() throws IOException, ExecutionException, InterruptedException { |
160 | 190 | ConfigFetcher fetch = new ConfigFetcher(new OkHttpClient.Builder() |
|
0 commit comments