@Test
public void testGetAdministrationTaskForBarcodeSimilarMedicationMatch()
{

  Mockito
      .when(medicationsDao.getMedicationIdForBarcode("999"))
      .thenReturn(999L);
  Mockito
      .when(medicationsTasksProvider.findAdministrationTasks(
          Collections.singleton("1"),
          testTime.minusHours(1),
          testTime.plusHours(1)))
      .thenReturn(Lists.newArrayList(buildTaskDto("333", "uid1|Medication instruction")));
  final Pair<MedicationOrderComposition, MedicationInstructionInstruction> instructionPair = buildInstructionPair(
      "uid1::1");
  Mockito
      .when(medicationsOpenEhrDao.getTherapyInstructionPairs(Sets.newHashSet("uid1")))
      .thenReturn(Lists.newArrayList(instructionPair));
  Mockito
      .when(medicationsBo.getMedicationIds(instructionPair.getSecond().getOrder().get(0)))
      .thenReturn(Lists.newArrayList(888L));
  Mockito
      .when(medicationsFinder.findMedicationProducts(888L, Lists.newArrayList(444L), testTime))
      .thenReturn(Lists.newArrayList(buildMedicationDto(888L), buildMedicationDto(999L)));
  final BarcodeTaskSearchDto dto = barcodeTaskFinder.getAdministrationTaskForBarcode("1", "999", testTime);
  assertEquals(BarcodeSearchResult.TASK_FOUND, dto.getBarcodeSearchResult());
  assertEquals("333", dto.getTaskId());
}