Skip to content

Commit 59ae91f

Browse files
author
martinmeerAT
committed
fix(Linter) is ok
1 parent 95c6c16 commit 59ae91f

File tree

3 files changed

+59
-26
lines changed

3 files changed

+59
-26
lines changed

src/test/java/org/martinmeer/otkassistant/core/service/SchemaAwareNamedParameterJdbcTemplateRealDbTest.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.martinmeer.otkassistant.core.service;
22

3-
43
import org.junit.jupiter.api.Tag;
54
import org.junit.jupiter.api.Test;
65
import org.martinmeer.otkassistant.MainApp;
@@ -13,7 +12,11 @@
1312
import java.math.BigDecimal;
1413
import java.util.Map;
1514

16-
import static org.junit.jupiter.api.Assertions.*;
15+
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.junit.jupiter.api.Assertions.assertNotNull;
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
18+
import static org.junit.jupiter.api.Assertions.assertTrue;
19+
1720

1821
@SpringBootTest(classes = {MainApp.class, SchemaAwareNamedParameterJdbcTemplateRealDbTest.class})
1922
@ActiveProfiles("test")
@@ -49,7 +52,6 @@ void testReadDataFromRealDb() {
4952
void testInvalidSchemaName() {
5053
// Arrange
5154
schemaAwareJdbc.setSchemaName("invalid@schema!");
52-
;
5355
String sql = "SELECT deviance FROM undef_deviances WHERE dim_range @> :id";
5456

5557
// Act & Assert
@@ -59,6 +61,7 @@ void testInvalidSchemaName() {
5961
BigDecimal.class);
6062
}, "Invalid schema name should throw IllegalArgumentException");
6163

62-
assertTrue(exception.getMessage().contains("Invalid schema name"), "Exception message should indicate invalid schema name");
64+
assertTrue(exception.getMessage().contains("Invalid schema name"),
65+
"Exception message should indicate invalid schema name");
6366
}
64-
}
67+
}

src/test/java/org/martinmeer/otkassistant/core/web/ApiControllerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void setUp() {
4141
}
4242

4343
@Test
44-
void processRequest_ValidInput_ReturnsServiceOutput() throws Exception {
44+
void processRequestValidInput() throws Exception {
4545
when(mainServiceFactory.getService("ost22")).thenReturn(mainService);
4646
when(mainService.generateOutput("ost22", "type:10.00"))
4747
.thenReturn(Map.of("result", "success"));
@@ -54,7 +54,7 @@ void processRequest_ValidInput_ReturnsServiceOutput() throws Exception {
5454
}
5555

5656
@Test
57-
void processRequest_UnknownPageId_ThrowsException() throws Exception {
57+
void processRequestUnknownPageIdThrowsException() throws Exception {
5858
// 1. Настраиваем мок фабрики на возврат null для неизвестного pageId
5959
String unknownPageId = "unknownPage";
6060
when(mainServiceFactory.getService(unknownPageId)).thenReturn(null);

src/test/java/org/martinmeer/otkassistant/ost22/service/OstMainServiceTest.java

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@
1515
import java.math.BigDecimal;
1616
import java.util.Map;
1717

18-
import static org.junit.jupiter.api.Assertions.*;
19-
import static org.mockito.ArgumentMatchers.*;
20-
import static org.mockito.Mockito.*;
18+
import static org.junit.jupiter.api.Assertions.assertAll;
19+
import static org.junit.jupiter.api.Assertions.assertEquals;
20+
import static org.junit.jupiter.api.Assertions.assertThrows;
21+
import static org.junit.jupiter.api.Assertions.assertTrue;
22+
import static org.mockito.ArgumentMatchers.anyMap;
23+
import static org.mockito.ArgumentMatchers.anyString;
24+
import static org.mockito.ArgumentMatchers.contains;
25+
import static org.mockito.ArgumentMatchers.eq;
26+
import static org.mockito.Mockito.lenient;
27+
import static org.mockito.Mockito.verify;
28+
import static org.mockito.Mockito.when;
29+
2130

2231
@ExtendWith(MockitoExtension.class)
2332
class OstMainServiceTest {
@@ -45,7 +54,9 @@ class OstMainServiceTest {
4554
@BeforeEach
4655
void setUp() throws NoSuchMethodException, NoSuchFieldException {
4756
// Access private method via reflection
48-
method = OstMainService.class.getDeclaredMethod("generateDefinedData", SchemaAwareNamedParameterJdbcTemplate.class);
57+
method = OstMainService.class.getDeclaredMethod(
58+
"generateDefinedData",
59+
SchemaAwareNamedParameterJdbcTemplate.class);
4960
method.setAccessible(true);
5061
nominalDimensionField = getField(OstMainService.class, "nominalDimension");
5162
dimensionDefinitionField = getField(OstMainService.class, "dimensionDefinition");
@@ -57,12 +68,20 @@ void setUp() throws NoSuchMethodException, NoSuchFieldException {
5768
}
5869

5970
@Test
60-
void generateDefinedData_ValidHoleDimension_SetsCorrectValues() throws Exception {
71+
void generateDefinedDataValidHoleDimensionSetsCorrectValues() throws Exception {
6172
// Arrange
62-
when(inputData.getDimensionDefinition()).thenReturn("hole");
63-
when(sqlBuilder.buildSelectSql()).thenReturn("SELECT hole FROM def_deviances WHERE nom_dim_range @> :value");
64-
when(jdbcTemplate.queryWithSchema(anyString(), anyMap(), eq(Boolean.class))).thenReturn(true);
65-
when(jdbcTemplate.queryWithSchema(anyString(), anyMap(), eq(BigDecimal.class))).thenReturn(new BigDecimal("0.05"));
73+
when(inputData.getDimensionDefinition())
74+
.thenReturn("hole");
75+
when(sqlBuilder.buildSelectSql())
76+
.thenReturn("SELECT hole FROM def_deviances WHERE nom_dim_range @> :value");
77+
when(jdbcTemplate.queryWithSchema(anyString(),
78+
anyMap(),
79+
eq(Boolean.class)))
80+
.thenReturn(true);
81+
when(jdbcTemplate.queryWithSchema(anyString(),
82+
anyMap(),
83+
eq(BigDecimal.class)))
84+
.thenReturn(new BigDecimal("0.05"));
6685

6786
// Act
6887
method.invoke(ostMainService, jdbcTemplate);
@@ -107,25 +126,36 @@ private void assertFieldValues(
107126
}
108127

109128
@Test
110-
void generateDefinedData_InvalidDimension_ThrowsException() throws Exception {
129+
void generateDefinedDataInvalidDimensionThrowsException() throws Exception {
111130
// Arrange
112131
when(inputData.getDimensionDefinition()).thenReturn("invalid_type");
113132

114133
// Act & Assert
115-
Exception exception = assertThrows(Exception.class, () -> method.invoke(ostMainService, jdbcTemplate));
116-
assertTrue(exception.getCause().getMessage().contains("Проверьте правильность типа введенных данных"));
134+
Exception exception = assertThrows(Exception.class,
135+
() -> method.invoke(ostMainService, jdbcTemplate));
136+
assertTrue(exception
137+
.getCause()
138+
.getMessage()
139+
.contains("Проверьте правильность типа введенных данных"));
117140
}
118141

119142
@Test
120-
void generateDefinedData_ValidationFailed_ThrowsException() throws Exception {
143+
void generateDefinedDataValidationFailedThrowsException() throws Exception {
121144
// Arrange
122145
when(inputData.getDimensionDefinition()).thenReturn("hole");
123-
when(sqlBuilder.buildSelectSql()).thenReturn("SELECT hole FROM def_deviances WHERE nom_dim_range @> :value");
124-
when(jdbcTemplate.queryWithSchema(anyString(), anyMap(), eq(Boolean.class))).thenReturn(false);
146+
when(sqlBuilder.buildSelectSql())
147+
.thenReturn("SELECT hole FROM def_deviances WHERE nom_dim_range @> :value");
148+
when(jdbcTemplate.queryWithSchema(anyString(),
149+
anyMap(),
150+
eq(Boolean.class))).thenReturn(false);
125151

126152
// Act & Assert
127-
Exception exception = assertThrows(Exception.class, () -> method.invoke(ostMainService, jdbcTemplate));
128-
assertTrue(exception.getCause().getMessage().contains("Проверьте правильность введенных данных"));
153+
Exception exception = assertThrows(Exception.class,
154+
() -> method.invoke(ostMainService, jdbcTemplate));
155+
assertTrue(exception
156+
.getCause()
157+
.getMessage()
158+
.contains("Проверьте правильность введенных данных"));
129159
}
130160

131161
private static Field getField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
@@ -135,7 +165,7 @@ private static Field getField(Class<?> clazz, String fieldName) throws NoSuchFie
135165
}
136166

137167
@Test
138-
void outputMapper_ReturnsCorrectValues() throws IllegalAccessException {
168+
void outputMapperReturnsCorrectValues() throws IllegalAccessException {
139169
// Arrange: Set required fields using reflection
140170
nominalDimensionField.set(ostMainService, new BigDecimal("20.0"));
141171
upperDevianceField.set(ostMainService, new BigDecimal("0.05"));
@@ -152,4 +182,4 @@ void outputMapper_ReturnsCorrectValues() throws IllegalAccessException {
152182
() -> assertEquals("19.95", result.get("min_mes_value"))
153183
);
154184
}
155-
}
185+
}

0 commit comments

Comments
 (0)