forked from I2P_Developers/i2p.i2p
SchedulerDead tests
This commit is contained in:
@ -90,6 +90,7 @@
|
||||
<include name="**/*.class"/>
|
||||
<!-- exclude Test classes -->
|
||||
<exclude name="**/*Test.class" />
|
||||
<exclude name="**/*TestBase.class" />
|
||||
<exclude name="**/*IT.class" />
|
||||
<exclude name="**/*IT$*.class" />
|
||||
<exclude name="**/StreamingITBase.class" />
|
||||
|
@ -0,0 +1,56 @@
|
||||
package net.i2p.client.streaming.impl;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
|
||||
public class SchedulerDeadTest extends SchedulerImplTestBase {
|
||||
|
||||
private SchedulerDead s;
|
||||
@Mock private Connection con;
|
||||
@Mock private ConnectionOptions opts;
|
||||
|
||||
protected void initScheduler() {
|
||||
s = new SchedulerDead(context);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccept_null() {
|
||||
assertFalse(s.accept(null));
|
||||
}
|
||||
|
||||
private void setMocks(int now, int discSchOn, int connTimeout, int lifetime, int sendStreamId) {
|
||||
when(clock.now()).thenReturn((long) now);
|
||||
when(con.getDisconnectScheduledOn()).thenReturn((long) discSchOn);
|
||||
when(con.getOptions()).thenReturn(opts);
|
||||
when(opts.getConnectTimeout()).thenReturn((long) connTimeout);
|
||||
when(con.getLifetime()).thenReturn((long) lifetime);
|
||||
when(con.getSendStreamId()).thenReturn((long) sendStreamId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccept_nothingLeftToDo() {
|
||||
setMocks(10*60*1000, 9*60*1000 - Connection.DISCONNECT_TIMEOUT, 0, 0, 0);
|
||||
assertTrue(s.accept(con));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccept_noDisconnectScheduled() {
|
||||
setMocks(10*60*1000, 0, 0, 0, 0);
|
||||
assertFalse(s.accept(con));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAccept_timedOut() {
|
||||
setMocks(0, 0, Connection.DISCONNECT_TIMEOUT/2, Connection.DISCONNECT_TIMEOUT, 0);
|
||||
assertTrue(s.accept(con));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEventOccurred() {
|
||||
s.eventOccurred(con);
|
||||
verify(con).disconnectComplete();
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package net.i2p.client.streaming.impl;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Clock;
|
||||
import net.i2p.util.SimpleTimer2;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnit;
|
||||
import org.mockito.junit.MockitoRule;
|
||||
|
||||
public abstract class SchedulerImplTestBase {
|
||||
|
||||
@Rule
|
||||
public MockitoRule rule = MockitoJUnit.rule();
|
||||
|
||||
@Spy protected I2PAppContext context = I2PAppContext.getGlobalContext();
|
||||
@Mock protected Clock clock;
|
||||
@Mock protected SimpleTimer2 timer;
|
||||
|
||||
protected SchedulerDead scheduler;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
when(context.clock()).thenReturn(clock);
|
||||
when(context.simpleTimer2()).thenReturn(timer);
|
||||
|
||||
initScheduler();
|
||||
}
|
||||
|
||||
protected abstract void initScheduler();
|
||||
}
|
Reference in New Issue
Block a user