Skip to content

Commit e516c36

Browse files
committed
Removed unused imports and fixed complexity error
1 parent 476577f commit e516c36

6 files changed

Lines changed: 27 additions & 36 deletions

File tree

backend/src/main/java/ca/bc/gov/nrs/ilcr/configuration/SecurityConfiguration.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ public class SecurityConfiguration {
2525
private static final String PATH_HEALTH = "/api/health";
2626
private static final String PATH_INFO = "/api/info";
2727

28-
private static final String[] PUBLIC_PATHS = {
29-
"/api",
30-
PATH_HEALTH,
31-
PATH_INFO,
32-
"/api/prometheus"
33-
};
34-
3528
@Bean
3629
// java:S4502 — Disabling CSRF is safe here: this is a stateless REST API (SessionCreationPolicy
3730
// .STATELESS below) authenticated by bearer JWTs in the Authorization header, with no session

backend/src/main/java/ca/bc/gov/nrs/ilcr/schedule1/Schedule1Service.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,8 @@ public Schedule1Response getSchedule1(long millId, int year, boolean callerMayEd
339339
// missing Schedule 3 — an empty map yields a null crown (no pre-fill) and null pulled costs.
340340
// First row per code wins (rows come back ordered by detail id) so a duplicate/corrupt row can't
341341
// make the crown volume or pulled costs depend on driver row order (legacy takes the first row).
342-
Map<Integer, DetailRow> sch3ByCode = new HashMap<>();
343-
for (DetailRow row : repository.findSchedule3Details(millId, year)) {
344-
if (row.costItemCode() != null) {
345-
sch3ByCode.putIfAbsent(row.costItemCode(), row);
346-
}
347-
}
342+
Map<Integer, DetailRow> sch3ByCode =
343+
firstRowPerCode(repository.findSchedule3Details(millId, year));
348344
DetailRow crownRow = sch3ByCode.get(CODE_SCH3_CROWN_TIMBER);
349345
BigDecimal sch3CrownVolume = crownRow == null ? null : crownRow.volume();
350346

@@ -487,6 +483,17 @@ public CheckStatusResponse checkSchedule1Status(long millId, int year) {
487483
return new CheckStatusResponse(requirementsMet, errors, warnings, message);
488484
}
489485

486+
/** First stored detail row per cost-item code (later duplicates ignored); null codes skipped. */
487+
private static Map<Integer, DetailRow> firstRowPerCode(List<DetailRow> rows) {
488+
Map<Integer, DetailRow> byCode = new HashMap<>();
489+
for (DetailRow row : rows) {
490+
if (row.costItemCode() != null) {
491+
byCode.putIfAbsent(row.costItemCode(), row);
492+
}
493+
}
494+
return byCode;
495+
}
496+
490497
/** First stored detail row per (non-Other) cost-item code; later duplicates are ignored. */
491498
private static Map<Integer, DetailRow> indexFirstByCode(List<DetailRow> details) {
492499
Map<Integer, DetailRow> byCode = new HashMap<>();

backend/src/test/java/ca/bc/gov/nrs/ilcr/schedule1/Schedule1CheckStatusServiceTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;
5-
import static org.junit.jupiter.api.Assertions.assertNull;
65
import static org.junit.jupiter.api.Assertions.assertTrue;
76
import static org.mockito.ArgumentMatchers.any;
87
import static org.mockito.ArgumentMatchers.anyString;

backend/src/test/java/ca/bc/gov/nrs/ilcr/schedule1/Schedule1ControllerTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import ca.bc.gov.nrs.ilcr.schedule1.dto.Schedule1Response;
1717
import ca.bc.gov.nrs.ilcr.security.SchedulePermissions;
1818
import java.util.Locale;
19-
import org.junit.jupiter.api.BeforeEach;
2019
import org.junit.jupiter.api.Test;
2120
import org.junit.jupiter.api.extension.ExtendWith;
21+
import org.mockito.InjectMocks;
2222
import org.mockito.Mock;
2323
import org.mockito.junit.jupiter.MockitoExtension;
2424
import org.springframework.context.MessageSource;
@@ -53,14 +53,9 @@ class Schedule1ControllerTest {
5353
@Mock
5454
private Authentication authentication;
5555

56+
@InjectMocks
5657
private Schedule1Controller controller;
5758

58-
@BeforeEach
59-
void setUp() {
60-
controller = new Schedule1Controller(
61-
millContextService, schedule1Service, permissions, messageSource);
62-
}
63-
6459
@Test
6560
void getSchedule1_validatesContext_derivesEditFlag_andReturnsDocument() {
6661
Schedule1Response doc = mock(Schedule1Response.class);

backend/src/test/java/ca/bc/gov/nrs/ilcr/schedule1/Schedule1OtherCostsControllerTest.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
import ca.bc.gov.nrs.ilcr.schedule1.dto.OtherCostsDocument;
1414
import ca.bc.gov.nrs.ilcr.security.SchedulePermissions;
1515
import java.util.Locale;
16-
import org.junit.jupiter.api.BeforeEach;
1716
import org.junit.jupiter.api.Test;
1817
import org.junit.jupiter.api.extension.ExtendWith;
18+
import org.mockito.InjectMocks;
1919
import org.mockito.Mock;
2020
import org.mockito.junit.jupiter.MockitoExtension;
2121
import org.springframework.context.MessageSource;
@@ -50,14 +50,9 @@ class Schedule1OtherCostsControllerTest {
5050
@Mock
5151
private Authentication authentication;
5252

53+
@InjectMocks
5354
private Schedule1OtherCostsController controller;
5455

55-
@BeforeEach
56-
void setUp() {
57-
controller = new Schedule1OtherCostsController(
58-
millContextService, schedule1Service, permissions, messageSource);
59-
}
60-
6156
private OtherCostsDocument mockDocEchoingMessage() {
6257
OtherCostsDocument doc = mock(OtherCostsDocument.class);
6358
when(doc.withMessage(any())).thenReturn(doc);

backend/src/test/java/ca/bc/gov/nrs/ilcr/schedule1/Schedule1OtherCostsServiceTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,32 +92,32 @@ void add_inheritsSharedVolume_andPersists() {
9292
stubRows(new BigDecimal("6000"), List.of());
9393
service.addOtherCost(MILL, YEAR, new OtherCostRequest("New Row", 1200), USER);
9494
// BR-06: the new row inherits the shared Other-Costs volume (6000).
95-
verify(repository).insertOtherCost(
96-
eq(SUMMARY), eq("New Row"), eq(1200), eq(new BigDecimal("6000")), eq(USER));
95+
verify(repository).insertOtherCost(SUMMARY, "New Row", 1200, new BigDecimal("6000"), USER);
9796
}
9897

9998
@Test
10099
void add_nullCostAccepted() {
101100
stubContext("D");
102101
stubRows(new BigDecimal("6000"), List.of());
103102
service.addOtherCost(MILL, YEAR, new OtherCostRequest("No cost row", null), USER);
104-
verify(repository).insertOtherCost(
105-
eq(SUMMARY), eq("No cost row"), eq(null), eq(new BigDecimal("6000")), eq(USER));
103+
verify(repository).insertOtherCost(SUMMARY, "No cost row", null, new BigDecimal("6000"), USER);
106104
}
107105

108106
@Test
109107
void add_nonDraft_throws409() {
110108
stubContext("S");
109+
OtherCostRequest request = new OtherCostRequest("x", 1);
111110
assertThrows(ScheduleNotEditableException.class,
112-
() -> service.addOtherCost(MILL, YEAR, new OtherCostRequest("x", 1), USER));
111+
() -> service.addOtherCost(MILL, YEAR, request, USER));
113112
}
114113

115114
@Test
116115
void update_unknownId_throws404() {
117116
stubContext("D");
118117
when(repository.updateOtherCost(999999, SUMMARY, "x", 1, USER)).thenReturn(0);
118+
OtherCostRequest request = new OtherCostRequest("x", 1);
119119
assertThrows(OtherCostNotFoundException.class,
120-
() -> service.updateOtherCost(MILL, YEAR, 999999, new OtherCostRequest("x", 1), USER));
120+
() -> service.updateOtherCost(MILL, YEAR, 999999, request, USER));
121121
}
122122

123123
@Test
@@ -144,8 +144,9 @@ void add_persistenceFailure_translatesToScheduleNotSaved() {
144144
doThrow(new DataIntegrityViolationException("boom"))
145145
.when(repository).insertOtherCost(eq(SUMMARY), any(), any(), any(), eq(USER));
146146

147+
OtherCostRequest request = new OtherCostRequest("x", 1);
147148
assertThrows(ScheduleNotSavedException.class,
148-
() -> service.addOtherCost(MILL, YEAR, new OtherCostRequest("x", 1), USER));
149+
() -> service.addOtherCost(MILL, YEAR, request, USER));
149150
}
150151

151152
@Test
@@ -169,8 +170,9 @@ void update_persistenceFailure_translatesToScheduleNotSaved() {
169170
when(repository.updateOtherCost(5051, SUMMARY, "x", 1, USER))
170171
.thenThrow(new DataIntegrityViolationException("boom"));
171172

173+
OtherCostRequest request = new OtherCostRequest("x", 1);
172174
assertThrows(ScheduleNotSavedException.class,
173-
() -> service.updateOtherCost(MILL, YEAR, 5051, new OtherCostRequest("x", 1), USER));
175+
() -> service.updateOtherCost(MILL, YEAR, 5051, request, USER));
174176
}
175177

176178
@Test

0 commit comments

Comments
 (0)