-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/shipper2 #4
Conversation
public interface CarRepository extends JpaRepository<Car, String> { | ||
import java.util.Optional; | ||
|
||
public interface CarRepository { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
꼭 인터페이스를 만들어야 하나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
@BeforeEach | ||
void setUp() throws Exception { | ||
this.truckerService = TruckerService.builder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@InjectMock @mock
|
||
class TruckerServiceTest { | ||
|
||
private TruckerService truckerService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private TruckerService truckerService; | |
@InjectMock | |
private TruckerService truckerService; | |
@Mock | |
private CarRepository carReposityr; | |
... |
|
||
@Test | ||
void createContract_성공하는_경우() { | ||
TruckerDTO.ContractRequest req = new TruckerDTO.ContractRequest(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TruckerDTO.ContractRequest req = new TruckerDTO.ContractRequest(); | |
// when | |
when(carRepository.findById(any())).thenReturn(Optional.OfNullable(..)); | |
TruckerDTO.ContractRequest req = new TruckerDTO.ContractRequest(); |
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Builder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트를 위해서 라이브코드를 고치는 것이 좋은 것인가?
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
@Builder | ||
public class TruckerService { | ||
|
||
private final CarRepository carRepository; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
서비스에서 다른 리포지토리를 호출 하는 것에 대해서
2. test 는 Mock 사용하도록 수정 3. repository 는 interface 만 사용하도록 수정
private final AccountService accountService; | ||
private final CarService carService; | ||
private final ContractService contractService; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
전 여전히 각각의 서비스들을 컨트롤러에 가져오는 것의 이점을 아직 잘 모르겠어요!! 이 경우에도 특정 URL은 하나의 서비스만 사용하는 것 같기도 하구요. :-)
String contractId = truckerService.createContract(req); | ||
ShipmentDTO.BasicInfo basicInfo = new ShipmentDTO.BasicInfo(); | ||
basicInfo.setShipmentStatus("ready"); | ||
ResponseEntity<ShipmentDTO.BasicInfo> basicInfoResponseEntity = new ResponseEntity<ShipmentDTO.BasicInfo>(basicInfo, HttpStatus.OK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
코드를 잠깐 봤는데, BasicInfoResponseEntity 자체를 mocking 해볼 수도 있을 것 같네요. :-) 이 얘기는 이따 멘토링 시간에 얘기해보죠. ㅎㅎ
ShipmentDTO.BasicInfo basicInfo = new ShipmentDTO.BasicInfo(); | ||
basicInfo.setShipmentStatus("ready"); | ||
ResponseEntity<ShipmentDTO.BasicInfo> basicInfoResponseEntity = new ResponseEntity<ShipmentDTO.BasicInfo>(basicInfo, HttpStatus.OK); | ||
Contract contract = Contract.builder().contractId("testId").build(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Contract contract = Contract.builder().contractId("testId").build(); | |
Contract contract = mock(Contract.class); | |
when(contract.getContractId()).thenReturn("testId"); |
ShipmentDTO.BasicInfo basicInfo = new ShipmentDTO.BasicInfo(); | ||
basicInfo.setShipmentStatus("ready"); | ||
ResponseEntity<ShipmentDTO.BasicInfo> basicInfoResponseEntity = new ResponseEntity<ShipmentDTO.BasicInfo>(basicInfo, HttpStatus.OK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ShipmentDTO.BasicInfo basicInfo = new ShipmentDTO.BasicInfo(); | |
basicInfo.setShipmentStatus("ready"); | |
ResponseEntity<ShipmentDTO.BasicInfo> basicInfoResponseEntity = new ResponseEntity<ShipmentDTO.BasicInfo>(basicInfo, HttpStatus.OK); | |
ShipmentDTO.BasicInfo basicInfo = mock(ShipmentDTO.BasicInfo.class); | |
when(basicInfo.getShipmentStatus()).thenReturn("ready"); | |
ResponseEntity<ShipmentDTO.BasicInfo> basicInfoResponseEntity = mock(...); | |
when(basicInfoReponseEntity.getBasicInfo()).thenReturn(basicInfo); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -16,12 +17,14 @@ public class CarService { | |||
|
|||
private final CarRepository carRepository; | |||
|
|||
@Async(value = "taskExecutor") | |||
public String createCar(TruckerDTO.CarRequest req) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public String createCar(TruckerDTO.CarRequest req) { | |
String car = createCar(...); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@async 어노테이션에 대해서 좀 더 생각해보면 좋을 것 같습니다.
Quality Gate failedFailed conditions See analysis details on SonarQube Cloud Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨어요! 전에 간략하게 말씀드렸던대로, protobuf를 하나의 모듈로 통합해서 공유하는 방법도 생각해보셨으면 좋겠습니다. :-)
No description provided.