Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. package com.capgemini.starterkit.service;
  2. import static org.junit.Assert.assertEquals;
  3. import static org.junit.Assert.assertNotNull;
  4.  
  5. import org.junit.Test;
  6. import org.junit.runner.RunWith;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.boot.test.context.SpringBootTest;
  9. import org.springframework.test.context.junit4.SpringRunner;
  10.  
  11. import com.capgemini.starterkit.dto.CarDto;
  12. import com.capgemini.starterkit.dto.CreateUpdateCarDto;
  13. import com.capgemini.starterkit.entity.Car;
  14. import com.capgemini.starterkit.service.CarService;
  15.  
  16. @RunWith(SpringRunner.class)
  17. @SpringBootTest
  18. public class CarServiceTest {
  19.  
  20. @Autowired
  21. CarService carService;
  22.  
  23. @Test
  24. public void testShouldFindCarById() {
  25. // given
  26. final int carId = 1;
  27. // when
  28. Car car = carService.findById(carId);
  29. // then
  30. assertNotNull(car);
  31. assertEquals("crossover", car.getCategory());
  32. }
  33.  
  34. @Test
  35. public void testShouldAddCar() {
  36. // given
  37. int countBefore = carService.findAllCars().size();
  38. System.out.println(countBefore);
  39. final CarDto carDto = new CarDto();
  40. // when
  41. CarDto savedCar = carService.addCar(carDto);
  42. // then
  43. assertNotNull(savedCar.getId());
  44. assertEquals(countBefore+1, carService.findAllCars().size());
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement