@Override protected void setUp() throws Exception { setSettings(); mockery = new Mockery(); upTracker = mockery.mock(BandwidthTracker.class); downTracker = mockery.mock(BandwidthTracker.class); dhtManager = mockery.mock(DHTManager.class); connectionServices = mockery.mock(ConnectionServices.class); networkManager = mockery.mock(NetworkManager.class); searchServices = mockery.mock(SearchServices.class); cManager = mockery.mock(ConnectionManager.class); final ScheduledExecutorService ses = new ScheduledExecutorServiceStub() { @Override public ScheduledFuture<?> scheduleWithFixedDelay( Runnable command, long initialDelay, long delay, TimeUnit unit) { if (delay == NodeAssignerImpl.TIMER_DELAY && initialDelay == 0) assignerRunnable = command; return null; } }; injector = LimeTestUtils.createInjectorNonEagerly( new AbstractModule() { @Override protected void configure() { bind(BandwidthTracker.class) .annotatedWith(Names.named("uploadTracker")) .toInstance(upTracker); bind(BandwidthTracker.class) .annotatedWith(Names.named("downloadTracker")) .toInstance(downTracker); bind(DHTManager.class).toInstance(dhtManager); bind(NetworkManager.class).toInstance(networkManager); bind(ConnectionServices.class).toInstance(connectionServices); bind(ScheduledExecutorService.class) .annotatedWith(Names.named("backgroundExecutor")) .toInstance(ses); bind(ConnectionManager.class).toInstance(cManager); bind(SearchServices.class).toInstance(searchServices); bind(Executor.class) .annotatedWith(Names.named("unlimitedExecutor")) .toInstance(immediateExecutor); } }); nodeAssigner = injector.getInstance(NodeAssigner.class); nodeAssigner.start(); assertNotNull(assignerRunnable); }
@Override protected void tearDown() throws Exception { nodeAssigner.stop(); }