@Test
public void getCDTooManyCommercialDeliveries() throws NoSuchFieldException, IllegalAccessException {

    final DbProduct fakeProduct = mock(DbProduct.class);
    when(fakeProduct.getDeliveries()).thenReturn(Arrays.asList(
            DataModelFactory.createDelivery(SAMPLE_NAME, SAMPLE_VERSION, LocalDate.now().toString(), Arrays.asList("one")),
            DataModelFactory.createDelivery(SAMPLE_NAME, SAMPLE_VERSION, "does-not-matter", Collections.emptyList())
    ));
    final RepositoryHandler repoHandler = mock(RepositoryHandler.class);
    when(repoHandler.getOneByQuery(anyString(), anyString(), any(Class.class))).thenReturn(Optional.of(fakeProduct));
    final DataFetchingUtils sut = new DataFetchingUtils();
    final Logger fakeLogger = mock(Logger.class);
    when(fakeLogger.isWarnEnabled()).thenReturn(true);
    InjectionUtils.injectField(sut, DataFetchingUtils.class, "LOG", fakeLogger);
    final Optional<Delivery> result = sut.getCommercialDelivery(repoHandler, SAMPLE_NAME, SAMPLE_VERSION);
    // An entry is selected
    assertTrue(result.isPresent());
    // A warning message is printed to log file
    ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);
    verify(fakeLogger, times(1)).warn(msgCaptor.capture());
    assertEquals(String.format("Multiple commercial version entries found for [%s] [%s]", SAMPLE_NAME, SAMPLE_VERSION), msgCaptor.getValue());
    // The first matching entry is picked
    assertEquals(1, result.get().getDependencies().size());
}