개요

미니 프로젝트에 헥사고날 아키텍처로 리팩토링 한다. 해당 내용 과정에서 헥사고날 아키텍처에 익숙해진다.

목적

요구사항

변경 된 패키지 구조

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 :)

💡 해결책

@ExtendWith({MockitoExtension.class})
class ShowOneItemServiceTest {

  public static final long ITEM_ID = 1L;

  @InjectMocks
  ShowOneItemService showOneItemUseCase;
  @Mock
  ShowOneItemPort showOneItemPort;
	//..
}