@Override protected void makeAttempt() throws ProtocolException, IOException { super.makeAttempt(); throw new IOException(); } };
@Test(expected = ProtocolException.class) public void testMakeOneAttempt() throws Exception { CountingExecutor exec = new CountingExecutor() { @Override protected void makeAttempt() throws ProtocolException, IOException { super.makeAttempt(); throw new ProtocolException("something happened", new MockHttpURLConnection(404)); } }; exec.setDelays(new int[]{1, 2, 3}); try { exec.makeAttempts(); } finally { assertEquals(exec.getCalls(), 1); } }
@Test(expected = IOException.class) public void testMakeAllAttemptsThrowIOException() throws Exception { CountingExecutor exec = new CountingExecutor() { @Override protected void makeAttempt() throws ProtocolException, IOException { super.makeAttempt(); throw new IOException(); } }; exec.setDelays(new int[]{1, 2, 3}); try { exec.makeAttempts(); } finally { assertEquals(exec.getCalls(), 4); } }
@Test(expected = ProtocolException.class) public void testMakeAllAttemptsThrowProtocolException() throws Exception { CountingExecutor exec = new CountingExecutor() { @Override protected void makeAttempt() throws ProtocolException, IOException { super.makeAttempt(); throw new ProtocolException("something happened", new MockHttpURLConnection(500)); } }; exec.setDelays(new int[]{1, 2, 3}); try { exec.makeAttempts(); } finally { assertEquals(exec.getCalls(), 4); } }
@Override protected void makeAttempt() throws ProtocolException, IOException { super.makeAttempt(); throw new ProtocolException("something happened", new MockHttpURLConnection(404)); } };
@Override protected void makeAttempt() throws ProtocolException, IOException { super.makeAttempt(); throw new ProtocolException("something happened", new MockHttpURLConnection(500)); } };
@Test public void testMakeAttempts() throws Exception { CountingExecutor exec = new CountingExecutor(); exec.setDelays(new int[]{1, 2, 3}); assertTrue(exec.makeAttempts()); assertEquals(exec.getCalls(), 1); }
@Test public void testSetDelays() { CountingExecutor exec = new CountingExecutor(); assertArrayEquals(exec.getDelays(), new int[]{500, 1000, 2000, 3000}); exec.setDelays(new int[]{1, 2, 3}); assertArrayEquals(exec.getDelays(), new int[]{1, 2, 3}); assertEquals(exec.getCalls(), 0); }