コード例 #1
0
  @Test
  @Ignore
  public void testGetDogsByOwner() {
    Customer customer1 = new Customer("Martin", "Sakac", "Purkynova 4", "111");
    Customer customer2 = new Customer("Martin", "Haha", "Purkynova 55", "9999");
    Dog dog1 = new Dog("Martin", "doga", new LocalDate(1998, 05, 22), customer1);
    Dog dog2 = new Dog("Martin", "doga", new LocalDate(1998, 05, 22), customer2);
    Dog dog3 = new Dog("Pepan", "doga", new LocalDate(1998, 05, 22), customer2);

    List<Dog> listAll = Arrays.asList(dog1, dog2, dog3);
    List<Dog> listExpected = Arrays.asList(dog2, dog3);

    Mockito.stub(dogDaoImplMock.getDogsByOwner(CustomerConverter.CustomerToCustomerDto(customer2)))
        .toReturn(listExpected);

    List<DogDto> listActual =
        dogService.getDogsByOwner(CustomerConverter.CustomerToCustomerDto(customer2));

    Mockito.verify(dogDaoImplMock)
        .getDogsByOwner(CustomerConverter.CustomerToCustomerDto(customer2));

    for (int i = 0; i < 2; i++) {
      assertDog(listExpected.get(i), listActual.get(i));
    }
  }
コード例 #2
0
 @Before
 public void setUp() {
   if (dogDaoImplMock == null) {
     throw new RuntimeException("Dao mock is null!");
   }
   if (dogService == null) {
     throw new RuntimeException("customer service is null!");
   }
   if (dogService.getDogDao() == null) {
     throw new RuntimeException("Injektovanie neprebehlo spravne!");
   }
   System.err.println("Kontrola prebehla bez problemov!");
 }
コード例 #3
0
 @Test
 public void testUpdateDog() {
   DogDto dogDto =
       new DogDto(
           1L,
           "Martin",
           "doga",
           new LocalDate(1998, 05, 22),
           CustomerConverter.CustomerToCustomerDto(
               new Customer("Martin", "Sakac", "Purkynova 4", "111")));
   ArgumentCaptor<Dog> captor = ArgumentCaptor.forClass(Dog.class);
   dogService.updateDog(dogDto);
   Mockito.verify(dogDaoImplMock).updateDog(captor.capture());
   assertDogCaptor(dogDto, captor);
 }
コード例 #4
0
  @Test
  public void testGetDog() {
    Dog dog =
        new Dog(
            "Martin",
            "doga",
            new LocalDate(1998, 05, 22),
            new Customer("Martin", "Sakac", "Purkynova 4", "111"));
    dog.setId(1L);

    Mockito.stub(dogDaoImplMock.getDog(Mockito.anyLong())).toReturn(dog);

    DogDto dogActual = dogService.getDogById(1L);
    Mockito.verify(dogDaoImplMock).getDog(1L);
    assertDog(dog, dogActual);
  }
コード例 #5
0
  @Test
  public void testGetAllDogs() {
    Dog dog1 =
        new Dog(
            "Martin",
            "doga",
            new LocalDate(1998, 05, 22),
            new Customer("Martin", "Sakac", "Purkynova 4", "111"));
    Dog dog2 =
        new Dog(
            "Martin",
            "doga",
            new LocalDate(1998, 05, 22),
            new Customer("Martin", "Sakac", "Purkynova 4", "111"));

    List<Dog> dogList = Arrays.asList(dog1, dog2);
    Mockito.stub(dogDaoImplMock.getAllDogs()).toReturn(dogList);
    List<DogDto> list = dogService.getAllDogs();
    Mockito.verify(dogDaoImplMock).getAllDogs();

    for (int i = 0; i < 2; i++) {
      assertDog(dogList.get(i), list.get(i));
    }
  }