Let's start with a unit test of a Java EE core component. The CarManufacturer boundary executes certain business logic and invokes a CarFactory delegate control:
@Stateless public class CarManufacturer { @Inject CarFactory carFactory; @PersistenceContext EntityManager entityManager; public Car manufactureCar(Specification spec) { Car car = carFactory.createCar(spec); entityManager.merge(car); return car; } }
Since the EJB boundary is a plain Java class, it can be instantiated and set up in a unit test. The most commonly used Java unit test technology is JUnit together with Mockito for mocking. The following code snippet shows the car manufacturer test case, instantiating the boundary test object and using Mockito to mock away ...