@Test
public void testChaining() {

    CellRouter first = Mockito.mock(CellRouter.class);
    CellRouter second = Mockito.mock(CellRouter.class);
    ChainCellRouter chain = new ChainCellRouter(asList(first, second));
    // Nothing matches
    when(first.routeKey(any())).thenReturn(Optional.empty());
    when(second.routeKey(any())).thenReturn(Optional.empty());
    assertThat(chain.routeKey(JobDescriptor.getDefaultInstance())).isEmpty();
    // First cell matches
    when(first.routeKey(any())).thenReturn(Optional.of(CELL_1));
    when(second.routeKey(any())).thenReturn(Optional.of(CELL_2));
    assertThat(chain.routeKey(JobDescriptor.getDefaultInstance())).contains(CELL_1);
    // Second cell matches
    when(first.routeKey(any())).thenReturn(Optional.empty());
    when(second.routeKey(any())).thenReturn(Optional.of(CELL_2));
    assertThat(chain.routeKey(JobDescriptor.getDefaultInstance())).contains(CELL_2);
}