미니 프로젝트에 헥사고날 아키텍처로 리팩토링 한다. 해당 내용 과정에서 헥사고날 아키텍처에 익숙해진다.
commerce
|__ item
|- adapter
| |- in
| | |__ web
| | |__ ItemRestController
| |- out
| | |__ persistence
| | |__ ItemPersistenceAdapter
|- domain |__ ItemRepository
| |__ Item
|
|__application
|__ SendMoneyService
|__ port
|- port
|- in
| |__ CreateItemUseCase
|__ out
|- CreateItemPort
Service 를 테스트하고자 할 때, UseCase 및 Port가 Mock으로 Inject되지 않음.
Cannot instantiate @InjectMocks field named 'showOneItemUseCase'! Cause: the type 'ShowOneItemUseCase' is an interface.
You haven't provided the instance at field declaration so I tried to construct the instance.
Examples of correct usage of @InjectMocks:
@InjectMocks Service service = new Service();
@InjectMocks Service service;
//and... don't forget about some @Mocks for injection :)
Mock
이 생성되지 않는다는 문제가 존재한다.@InjectMocks Service service = new Service()
와 같다고 알려주고 있음.💡 해결책
@ExtendWith({MockitoExtension.class})
class ShowOneItemServiceTest {
public static final long ITEM_ID = 1L;
@InjectMocks
ShowOneItemService showOneItemUseCase;
@Mock
ShowOneItemPort showOneItemPort;
//..
}
UseCase
와 같은 인터페이스가 아닌 인스턴스화 할 수 있는 Service
를 테스트 하기로 함.