@Test public void testDispatchSuccessOfFirst() { TransmissionOutputAsync mockOutput1 = Mockito.mock(TransmissionOutputAsync.class); Mockito.doReturn(true).when(mockOutput1).sendAsync((Transmission) anyObject()); TransmissionOutputAsync mockOutput2 = Mockito.mock(TransmissionOutputAsync.class); NonBlockingDispatcher tested = new NonBlockingDispatcher(new TransmissionOutputAsync[] {mockOutput1, mockOutput2}); Transmission transmission = new Transmission(new byte[2], "mockType", "mockEncoding"); tested.dispatch(transmission); Mockito.verify(mockOutput1, Mockito.times(1)).sendAsync((Transmission) anyObject()); Mockito.verify(mockOutput2, Mockito.never()).sendAsync((Transmission) anyObject()); }
@Override public void dispatch(Transmission transmission) { Preconditions.checkNotNull(transmission, "transmission should be non-null value"); for (TransmissionOutputAsync output : transmissionOutputs) { if (output.sendAsync(transmission)) { return; } } }
NonBlockingDispatcher implements TransmissionDispatcher { @Override public void dispatch(Transmission transmission) { Preconditions.checkNotNull(transmission, "transmission should be non-null value"); for (TransmissionOutputAsync output : transmissionOutputs) { if (output.sendAsync(transmission)) { return; } } } }
NonBlockingDispatcher implements TransmissionDispatcher { @Override public void dispatch(Transmission transmission) { Preconditions.checkNotNull(transmission, "transmission should be non-null value"); for (TransmissionOutputAsync output : transmissionOutputs) { if (output.sendAsync(transmission)) { return; } } } NonBlockingDispatcher(TransmissionOutputAsync[] transmissionOutputs); }
NonBlockingDispatcher implements TransmissionDispatcher { @Override public void dispatch(Transmission transmission) { Preconditions.checkNotNull(transmission, "transmission should be non-null value"); for (TransmissionOutputAsync output : transmissionOutputs) { if (output.sendAsync(transmission)) { return; } } } NonBlockingDispatcher(TransmissionOutputAsync[] transmissionOutputs); @Override void dispatch(Transmission transmission); @Override void shutdown(long timeout, TimeUnit timeUnit); }
NonBlockingDispatcher implements TransmissionDispatcher { @Override public void dispatch(Transmission transmission) { Preconditions.checkNotNull(transmission, "transmission should be non-null value"); for (TransmissionOutputAsync output : transmissionOutputs) { if (output.sendAsync(transmission)) { return; } } } NonBlockingDispatcher(TransmissionOutputAsync[] transmissionOutputs); @Override void dispatch(Transmission transmission); @Override void shutdown(long timeout, TimeUnit timeUnit);  }