@Test public void test() { Specification spec = new Specification(); Car car = new Car(spec); when(testObject.entityManager.merge(any())).then(a -> a.getArgument(0)); when(testObject.carFactory.createCar(any())).thenReturn(car); assertThat(testObject.manufactureCar(spec)).isEqualTo(car); verify(testObject.carFactory).createCar(spec); verify(testObject.entityManager).merge(car); }
public Car manufactureCar(Specification spec) { Car car = carFactory.createCar(spec); entityManager.merge(car); return car; }
CarManufacturer { public Car manufactureCar(Specification spec) { Car car = carFactory.createCar(spec); entityManager.merge(car); return car; } }
CarManufacturer { public Car manufactureCar(Specification spec) { Car car = carFactory.createCar(spec); entityManager.merge(car); return car; }  }
CarManufacturer { public Car manufactureCar(Specification spec) { Car car = carFactory.createCar(spec); entityManager.merge(car); return car; }  Car manufactureCar(Specification spec); }
CarManufacturer { public Car manufactureCar(Specification spec) { Car car = carFactory.createCar(spec); entityManager.merge(car); return car; }  Car manufactureCar(Specification spec);  }