|
@@ -9,6 +9,7 @@ import org.mockito.ArgumentCaptor;
|
|
|
import org.mockito.Mock;
|
|
import org.mockito.Mock;
|
|
|
import org.mockito.MockitoAnnotations;
|
|
import org.mockito.MockitoAnnotations;
|
|
|
|
|
|
|
|
|
|
+import java.io.Serializable;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
import static org.junit.jupiter.api.Assertions.*;
|
|
@@ -147,13 +148,15 @@ public class FoodRecommendServiceTest {
|
|
|
FoodRecommendIndex existing = mockIndex(1L, 100L, "食材A", 80);
|
|
FoodRecommendIndex existing = mockIndex(1L, 100L, "食材A", 80);
|
|
|
FoodRecommendIndex existing2 = mockIndex(1L, 200L, "食材B", 75);
|
|
FoodRecommendIndex existing2 = mockIndex(1L, 200L, "食材B", 75);
|
|
|
when(healthReportService.getLatestReport(1L)).thenReturn(report);
|
|
when(healthReportService.getLatestReport(1L)).thenReturn(report);
|
|
|
- when(reportFoodSuitabilityMapper.selectList(any())).thenReturn(Collections.emptyList()); // no suit data
|
|
|
|
|
|
|
+ // 新报告只含食材C,existing A/B 被移除
|
|
|
|
|
+ ReportFoodSuitability newSuit = mockSuit(1L, 300L, "食材C", 70);
|
|
|
|
|
+ when(reportFoodSuitabilityMapper.selectList(any())).thenReturn(Collections.singletonList(newSuit));
|
|
|
when(foodRecommendIndexMapper.selectList(any())).thenReturn(Arrays.asList(existing, existing2));
|
|
when(foodRecommendIndexMapper.selectList(any())).thenReturn(Arrays.asList(existing, existing2));
|
|
|
|
|
|
|
|
service.recalculateForUser(1L);
|
|
service.recalculateForUser(1L);
|
|
|
|
|
|
|
|
// Both should be deleted and logged
|
|
// Both should be deleted and logged
|
|
|
- verify(foodRecommendIndexMapper, times(2)).deleteById(any());
|
|
|
|
|
|
|
+ verify(foodRecommendIndexMapper, times(2)).deleteById(any(Serializable.class));
|
|
|
verify(foodRecommendIdxLogMapper, times(2)).insert(any());
|
|
verify(foodRecommendIdxLogMapper, times(2)).insert(any());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -196,8 +199,8 @@ public class FoodRecommendServiceTest {
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void getByFamily_returnsAllMemberIndices() {
|
|
public void getByFamily_returnsAllMemberIndices() {
|
|
|
- FamilyMember m1 = mockMember(1L, 1L); // memberId=1, userId=10
|
|
|
|
|
- FamilyMember m2 = mockMember(2L, 2L); // memberId=2, userId=20
|
|
|
|
|
|
|
+ FamilyMember m1 = mockMember(1L, 10L);
|
|
|
|
|
+ FamilyMember m2 = mockMember(2L, 20L);
|
|
|
FoodRecommendIndex idx1 = mockIndex(10L, 100L, "食材A", 80);
|
|
FoodRecommendIndex idx1 = mockIndex(10L, 100L, "食材A", 80);
|
|
|
FoodRecommendIndex idx2 = mockIndex(20L, 200L, "食材B", 75);
|
|
FoodRecommendIndex idx2 = mockIndex(20L, 200L, "食材B", 75);
|
|
|
when(familyMemberMapper.selectList(any())).thenReturn(Arrays.asList(m1, m2));
|
|
when(familyMemberMapper.selectList(any())).thenReturn(Arrays.asList(m1, m2));
|