import java.io.File;
import java.io.IOException;
import java.net.ConnectException;
+import java.net.SocketTimeoutException;
import java.util.Properties;
+import static org.junit.Assert.*;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
str = connection.downloadStringCache("/batch/index.txt");
assertThat(str).isEqualTo("abcde");
}
-
+
@Test
public void should_throw_connection_exception_() throws IOException {
File cacheDir = new File(temp.getRoot(), "ws_cache");
ServerConnection connection = ServerConnection.create(props, cache, mock(Logger.class));
String str = connection.downloadStringCache("/batch/index.txt");
assertThat(str).isEqualTo("abcde");
-
+
httpServer.after();
-
+
try {
connection.downloadStringCache("/batch/index.txt");
fail("exception expected");
- } catch(HttpRequest.HttpRequestException e) {
- //expected
- assertThat(e.getCause()).isInstanceOf(ConnectException.class);
-
- //cache never used
+ } catch (HttpRequest.HttpRequestException e) {
+ // expected
+ assertTrue((e.getCause() instanceof ConnectException) || (e.getCause() instanceof SocketTimeoutException));
+
+ // cache never used
assertThat(cacheDir.list().length).isEqualTo(0);
}
-
+
}
@Test