From 5237bb713d3e83e1ac7e7004cf7a52c0936dcb71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B2=85?= <907037276@qq.com> Date: Wed, 26 Aug 2026 15:09:07 +0800 Subject: [PATCH] test: cover market opportunity score validation --- ...MarketOpportunitySelectionStepThreeServiceImplTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/com/sztzjy/linkCommerce/service/impl/MarketOpportunitySelectionStepThreeServiceImplTest.java b/src/test/java/com/sztzjy/linkCommerce/service/impl/MarketOpportunitySelectionStepThreeServiceImplTest.java index 517849d..abdff2c 100644 --- a/src/test/java/com/sztzjy/linkCommerce/service/impl/MarketOpportunitySelectionStepThreeServiceImplTest.java +++ b/src/test/java/com/sztzjy/linkCommerce/service/impl/MarketOpportunitySelectionStepThreeServiceImplTest.java @@ -33,6 +33,13 @@ class MarketOpportunitySelectionStepThreeServiceImplTest { MarketOpportunitySelectionStepThreeServiceImpl service = new MarketOpportunitySelectionStepThreeServiceImpl(); StudentTrainingAnswerService answers = mock(StudentTrainingAnswerService.class); ReflectionTestUtils.setField(service, "studentTrainingAnswerService", answers); when(answers.get(anyString(), any(), any(JwtUser.class))).thenReturn(null); assertThrows(ServiceException.class, () -> service.validate(completedRequest(), student())); } + @Test + void validateRejectsUnknownOrDuplicateProductCategories() { + MarketOpportunitySelectionStepThreeValidationRequest unknownCategory = completedRequest(); unknownCategory.getScores().get(2).setId("unknown-category"); + assertThrows(ServiceException.class, () -> serviceWithStepTwo().validate(unknownCategory, student())); + MarketOpportunitySelectionStepThreeValidationRequest duplicateCategory = completedRequest(); duplicateCategory.getScores().get(2).setId("smart-fitness-mirror"); + assertThrows(ServiceException.class, () -> serviceWithStepTwo().validate(duplicateCategory, student())); + } private MarketOpportunitySelectionStepThreeServiceImpl serviceWithStepTwo() { MarketOpportunitySelectionStepThreeServiceImpl service = new MarketOpportunitySelectionStepThreeServiceImpl(); StudentTrainingAnswerService answers = mock(StudentTrainingAnswerService.class); StudentTrainingAnswer answer = new StudentTrainingAnswer(); answer.setStep2Answer("{\"primaryWeights\":{\"市场规模\":25,\"市场潜力\":25,\"竞争强度\":25,\"运营难度\":25},\"dimensionWeights\":{\"search-count\":50,\"transaction-amount\":50,\"transaction-growth\":50,\"category-transaction-growth\":50,\"demand-supply-ratio\":34,\"online-products\":33,\"online-merchants\":33,\"organic-traffic-ratio\":50,\"return-rate\":50}}"); when(answers.get(anyString(), any(), any(JwtUser.class))).thenReturn(answer); ReflectionTestUtils.setField(service, "studentTrainingAnswerService", answers); return service; } private MarketOpportunitySelectionStepThreeValidationRequest completedRequest() { MarketOpportunitySelectionStepThreeValidationRequest request = new MarketOpportunitySelectionStepThreeValidationRequest(); ArrayList scores = new ArrayList<>(); Arrays.asList("smart-fitness-mirror", "smart-bathroom-mirror", "smart-beauty-mirror").forEach(id -> { MarketOpportunitySelectionStepThreeValidationRequest.Score score = new MarketOpportunitySelectionStepThreeValidationRequest.Score(); score.setId(id); score.setScore(new BigDecimal("86.50")); scores.add(score); }); request.setScores(scores); return request; } private JwtUser student() { JwtUser user = new JwtUser(); user.setUserId("stu-1"); user.setRoleId(4); return user; }