MultiStereoEncoder implements StereoEncoder { @Override public boolean encode(long[] current, long[] next) { boolean configured = false; for (int i = unconfigured.nextSetBit(0); i >= 0; i = unconfigured.nextSetBit(i + 1)) { if (encoders.get(i).encode(current, next)) { unconfigured.clear(i); configured = true; } } return configured; } MultiStereoEncoder(List<StereoEncoder> encoders); @Override boolean encode(long[] current, long[] next); @Override void reset();  }
@Test public void testEncode() throws Exception { StereoEncoder a = mock(StereoEncoder.class); StereoEncoder b = mock(StereoEncoder.class); StereoEncoder encoder = new MultiStereoEncoder(Arrays.asList(a, b)); long[] current = new long[5]; long[] next = new long[5]; when(a.encode(current, next)).thenReturn(true); when(b.encode(current, next)).thenReturn(true); assertTrue(encoder.encode(current, next)); assertFalse(encoder.encode(current, next)); verify(a, times(1)).encode(current, next); verify(b, times(1)).encode(current, next); }