1515import java .math .BigDecimal ;
1616import 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 )
2332class 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