Fix waiting for connections.
[xudocci.git] / src / test / java / net / pterodactylus / xdcc / core / ConnectionBackoffTest.java
index adaae8b..91b1c82 100644 (file)
@@ -17,7 +17,8 @@ import org.mockito.Mockito;
 public class ConnectionBackoffTest {
 
        private final Network network = Mockito.mock(Network.class);
-       private final Clock fixedClock = Clock.fixed(Instant.now(), ZoneId.systemDefault());
+       private final Instant now = Instant.now();
+       private final Clock fixedClock = Clock.fixed(now, ZoneId.systemDefault());
        private final ConnectionBackoff connectionBackoff = new ConnectionBackoff(fixedClock);
 
        @Test
@@ -28,12 +29,14 @@ public class ConnectionBackoffTest {
        @Test
        public void firstConnectionIsImmediatelyPossible() {
                MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(0L));
+               MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli()));
        }
 
        @Test
        public void afterTheFirstFailedConnectionBackoffIsOneMinute() {
                connectionBackoff.connectionFailed(network);
                MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(60000L));
+               MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli() + 60000));
        }
 
        @Test
@@ -41,6 +44,7 @@ public class ConnectionBackoffTest {
                connectionBackoff.connectionFailed(network);
                connectionBackoff.connectionFailed(network);
                MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(72000L));
+               MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli() + 72000));
        }
 
        @Test
@@ -48,6 +52,7 @@ public class ConnectionBackoffTest {
                connectionBackoff.connectionFailed(network);
                connectionBackoff.connectionSuccessful(network);
                MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(0L));
+               MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli()));
        }
 
        @Test
@@ -56,6 +61,7 @@ public class ConnectionBackoffTest {
                        connectionBackoff.connectionFailed(network);
                }
                MatcherAssert.assertThat(connectionBackoff.getBackoff(network), Matchers.is(3600000L));
+               MatcherAssert.assertThat(connectionBackoff.getConnectionTime(network), Matchers.is(now.toEpochMilli() + 3600000));
        }
 
 }