|
|
@@ -2,11 +2,14 @@ package com.ruoyi.web.modules.industryservice.service.impl;
|
|
2
|
2
|
|
|
3
|
3
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
4
|
4
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
5
|
+import static org.mockito.ArgumentMatchers.eq;
|
|
5
|
6
|
import static org.mockito.ArgumentMatchers.any;
|
|
6
|
7
|
import static org.mockito.ArgumentMatchers.anyList;
|
|
|
8
|
+import static org.mockito.Mockito.lenient;
|
|
7
|
9
|
import static org.mockito.Mockito.when;
|
|
8
|
10
|
|
|
9
|
11
|
import java.math.BigDecimal;
|
|
|
12
|
+import java.time.Year;
|
|
10
|
13
|
import java.util.Arrays;
|
|
11
|
14
|
import java.util.Collections;
|
|
12
|
15
|
import org.junit.jupiter.api.DisplayName;
|
|
|
@@ -21,6 +24,7 @@ import com.ruoyi.web.modules.industryservice.domain.vo.BreedingIndustryDashboard
|
|
21
|
24
|
import com.ruoyi.web.modules.industryservice.mapper.BreedingIndustryStatsMapper;
|
|
22
|
25
|
import com.ruoyi.web.modules.industryservice.support.BreedingIndustryPastureScope;
|
|
23
|
26
|
import com.ruoyi.web.modules.industryservice.support.BreedingIndustryRules;
|
|
|
27
|
+import com.ruoyi.web.modules.screen.mapper.HomeScreenStatsMapper;
|
|
24
|
28
|
|
|
25
|
29
|
@ExtendWith(MockitoExtension.class)
|
|
26
|
30
|
@DisplayName("BreedingIndustryDashboardServiceImpl")
|
|
|
@@ -32,6 +36,9 @@ class BreedingIndustryDashboardServiceImplTest
|
|
32
|
36
|
@Mock
|
|
33
|
37
|
private BreedingIndustryPastureScope breedingIndustryPastureScope;
|
|
34
|
38
|
|
|
|
39
|
+ @Mock
|
|
|
40
|
+ private HomeScreenStatsMapper homeScreenStatsMapper;
|
|
|
41
|
+
|
|
35
|
42
|
@InjectMocks
|
|
36
|
43
|
private BreedingIndustryDashboardServiceImpl service;
|
|
37
|
44
|
|
|
|
@@ -39,20 +46,48 @@ class BreedingIndustryDashboardServiceImplTest
|
|
39
|
46
|
@DisplayName("ZCZX-YZCYSJ-UT-002 可见牧场为空")
|
|
40
|
47
|
void ut002_emptyScope()
|
|
41
|
48
|
{
|
|
|
49
|
+ int currentYear = Year.now().getValue();
|
|
42
|
50
|
stubGrassland();
|
|
|
51
|
+ stubReportOverviewSums(currentYear, 100, 50, 20);
|
|
43
|
52
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds()).thenReturn(Collections.emptyList());
|
|
44
|
53
|
BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
45
|
|
- assertEquals(0, vo.getOverview().getInventoryTotal());
|
|
46
|
|
- assertEquals(0, vo.getOverview().getPastureCount());
|
|
|
54
|
+ assertEquals(100, vo.getOverview().getInventoryTotal());
|
|
|
55
|
+ assertEquals(50, vo.getOverview().getAnnualOutbound());
|
|
|
56
|
+ assertEquals(20, vo.getOverview().getPastureCount());
|
|
47
|
57
|
assertEquals(3, vo.getOverview().getGrasslandCount());
|
|
48
|
58
|
assertEquals(0, vo.getInventoryChange().getMonthlyTrend().size());
|
|
49
|
59
|
}
|
|
50
|
60
|
|
|
51
|
61
|
@Test
|
|
52
|
|
- @DisplayName("ZCZX-YZCYSJ-UT-009 公母未标=总量")
|
|
|
62
|
+ @DisplayName("ZCZX-YZCYSJ-UT-028 产业总览三项与大屏填报口径一致")
|
|
|
63
|
+ void ut028_overviewFromReportTables()
|
|
|
64
|
+ {
|
|
|
65
|
+ int currentYear = Year.now().getValue();
|
|
|
66
|
+ stubGrassland();
|
|
|
67
|
+ stubReportOverviewSums(currentYear, 50000, 3200, 8988);
|
|
|
68
|
+ when(breedingIndustryPastureScope.resolveAllowedPastureIds())
|
|
|
69
|
+ .thenReturn(Collections.singletonList(BreedingIndustryTestSamples.PASTURE_P1));
|
|
|
70
|
+ when(breedingIndustryStatsMapper.countPastureInScope(anyList())).thenReturn(12);
|
|
|
71
|
+ when(breedingIndustryStatsMapper.countInventory(anyList())).thenReturn(3);
|
|
|
72
|
+ when(breedingIndustryStatsMapper.countAnnualOutbound(anyList(), any(), any())).thenReturn(8);
|
|
|
73
|
+ when(breedingIndustryStatsMapper.countWarningYak(anyList(), any(), any())).thenReturn(0);
|
|
|
74
|
+ when(breedingIndustryStatsMapper.selectYakSnapshotsInScope(anyList()))
|
|
|
75
|
+ .thenReturn(Collections.singletonList(BreedingIndustryTestSamples.normalBull()));
|
|
|
76
|
+
|
|
|
77
|
+ BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
|
78
|
+
|
|
|
79
|
+ assertEquals(50000, vo.getOverview().getInventoryTotal());
|
|
|
80
|
+ assertEquals(3200, vo.getOverview().getAnnualOutbound());
|
|
|
81
|
+ assertEquals(8988, vo.getOverview().getPastureCount());
|
|
|
82
|
+ }
|
|
|
83
|
+
|
|
|
84
|
+ @Test
|
|
|
85
|
+ @DisplayName("ZCZX-YZCYSJ-UT-009 公母未标=原存栏时点总量")
|
|
53
|
86
|
void ut009_genderSum()
|
|
54
|
87
|
{
|
|
|
88
|
+ int currentYear = Year.now().getValue();
|
|
55
|
89
|
stubGrassland();
|
|
|
90
|
+ stubReportOverviewSums(currentYear, 0, 0, 0);
|
|
56
|
91
|
when(breedingIndustryPastureScope.resolveAllowedPastureIds())
|
|
57
|
92
|
.thenReturn(Collections.singletonList(BreedingIndustryTestSamples.PASTURE_P1));
|
|
58
|
93
|
when(breedingIndustryStatsMapper.countPastureInScope(anyList())).thenReturn(1);
|
|
|
@@ -64,7 +99,6 @@ class BreedingIndustryDashboardServiceImplTest
|
|
64
|
99
|
BreedingIndustryTestSamples.normalCow(),
|
|
65
|
100
|
BreedingIndustryTestSamples.unknownGender()));
|
|
66
|
101
|
BreedingIndustryDashboardVo vo = service.loadDashboard(false);
|
|
67
|
|
- assertEquals(3, vo.getOverview().getInventoryTotal());
|
|
68
|
102
|
assertEquals(1, vo.getInventoryChange().getBullCount());
|
|
69
|
103
|
assertEquals(1, vo.getInventoryChange().getCowCount());
|
|
70
|
104
|
assertEquals(1, vo.getInventoryChange().getUnknownGenderCount());
|
|
|
@@ -88,4 +122,14 @@ class BreedingIndustryDashboardServiceImplTest
|
|
88
|
122
|
when(breedingIndustryStatsMapper.countInUseGrassland(any())).thenReturn(1);
|
|
89
|
123
|
when(breedingIndustryStatsMapper.selectDegradationGroupCounts()).thenReturn(Collections.emptyList());
|
|
90
|
124
|
}
|
|
|
125
|
+
|
|
|
126
|
+ private void stubReportOverviewSums(int currentYear, int inventory, int outbound, int farmerHousehold)
|
|
|
127
|
+ {
|
|
|
128
|
+ lenient().when(homeScreenStatsMapper.sumHerdInventoryYakTotalByStatYear(eq(currentYear - 1)))
|
|
|
129
|
+ .thenReturn(inventory);
|
|
|
130
|
+ lenient().when(homeScreenStatsMapper.sumOutboundReportYakCountByStatYear(eq(currentYear)))
|
|
|
131
|
+ .thenReturn(outbound);
|
|
|
132
|
+ lenient().when(homeScreenStatsMapper.sumOutboundReportFarmerHouseholdCountByStatYear(eq(currentYear)))
|
|
|
133
|
+ .thenReturn(farmerHousehold);
|
|
|
134
|
+ }
|
|
91
|
135
|
}
|