@Before public void before() { expectedCars = new ArrayList<>(); expectedCars.add(new Car(1, "Moskvich")); carsExportMocked = mock(CarsExport.class); carsDaoMocked = mock(CarsDao.class); carService = new CarServiceImpl(); carService.setCarsDao(carsDaoMocked); carService.setCarsExport(carsExportMocked); when(carsDaoMocked.getAllCars()).thenReturn(expectedCars); }
@Test public void testExport() throws Exception { carService.export(); verify(carsDaoMocked).getAllCars(); verify(carsExportMocked).export(expectedCars); }
@Test public void testGetCars() throws Exception { List<Car> actualCars = carService.getCars(); assertEquals(expectedCars, actualCars); }