Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.capgemini.starterkit.service;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.boot.test.context.SpringBootTest;
- import org.springframework.test.context.junit4.SpringRunner;
- import com.capgemini.starterkit.dto.CarDto;
- import com.capgemini.starterkit.dto.CreateUpdateCarDto;
- import com.capgemini.starterkit.entity.Car;
- import com.capgemini.starterkit.service.CarService;
- @RunWith(SpringRunner.class)
- @SpringBootTest
- public class CarServiceTest {
- @Autowired
- CarService carService;
- @Test
- public void testShouldFindCarById() {
- // given
- final int carId = 1;
- // when
- Car car = carService.findById(carId);
- // then
- assertNotNull(car);
- assertEquals("crossover", car.getCategory());
- }
- @Test
- public void testShouldAddCar() {
- // given
- int countBefore = carService.findAllCars().size();
- System.out.println(countBefore);
- final CarDto carDto = new CarDto();
- // when
- CarDto savedCar = carService.addCar(carDto);
- // then
- assertNotNull(savedCar.getId());
- assertEquals(countBefore+1, carService.findAllCars().size());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement