-
Notifications
You must be signed in to change notification settings - Fork 86
update jwtutil #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
update jwtutil #302
Changes from 2 commits
7dfdd6b
d52fa92
14af250
6bd136f
6729387
7c3cc9f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,357 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| package com.tinyengine.it.dynamic.service; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import cn.hutool.core.util.ReflectUtil; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.tinyengine.it.common.context.LoginUserContext; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.tinyengine.it.dynamic.dto.DynamicDelete; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.tinyengine.it.dynamic.dto.DynamicInsert; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.tinyengine.it.dynamic.dto.DynamicQuery; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.tinyengine.it.dynamic.dto.DynamicUpdate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.tinyengine.it.model.dto.ParametersDto; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import com.tinyengine.it.model.entity.Model; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.BeforeEach; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.Test; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.mockito.InjectMocks; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.mockito.Mock; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.mockito.MockitoAnnotations; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.jdbc.core.JdbcTemplate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.jdbc.core.PreparedStatementCreator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import org.springframework.jdbc.support.KeyHolder; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import java.util.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.junit.jupiter.api.Assertions.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.mockito.ArgumentMatchers.any; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.mockito.ArgumentMatchers.anyString; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import static org.mockito.Mockito.*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class DynamicModelServiceTest { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Mock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private JdbcTemplate jdbcTemplate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Mock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private NamedParameterJdbcTemplate namedParameterJdbcTemplate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Mock | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private LoginUserContext loginUserContext; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @InjectMocks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private DynamicModelService dynamicModelService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @BeforeEach | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void setUp() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MockitoAnnotations.openMocks(this); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| MockitoAnnotations.openMocks(this); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ReflectUtil.setFieldValue(dynamicModelService, "jdbcTemplate", jdbcTemplate); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ReflectUtil.setFieldValue(dynamicModelService, "loginUserContext", loginUserContext); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ReflectUtil.setFieldValue(dynamicModelService, "namedParameterJdbcTemplate", namedParameterJdbcTemplate); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void createDynamicTable() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Model model = new Model(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ParametersDto parametersDto = new ParametersDto(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setProp("name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setType("String"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setRequired(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setDefaultValue("1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setDescription("1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model.setParameters(Collections.singletonList(parametersDto)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Mock JdbcTemplate behavior | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doNothing().when(jdbcTemplate).execute(anyString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act & Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertDoesNotThrow(() -> dynamicModelService.createDynamicTable(model)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).execute(anyString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void dropDynamicTable() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Model model = new Model(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Mock JdbcTemplate behavior | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doNothing().when(jdbcTemplate).execute(anyString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act & Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertDoesNotThrow(() -> dynamicModelService.dropDynamicTable(model)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).execute("DROP TABLE IF EXISTS dynamic_test_table;"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void initializeDynamicTable() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Model model = new Model(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ParametersDto param1 = new ParametersDto(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| param1.setProp("name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| param1.setType("String"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| param1.setDefaultValue("default_name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| param1.setRequired(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model.setParameters(Collections.singletonList(param1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Long userId = 1L; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Mock JdbcTemplate behavior | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(jdbcTemplate.update(anyString(), any(Object[].class))).thenReturn(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act & Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertDoesNotThrow(() -> dynamicModelService.initializeDynamicTable(model, userId)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).update(anyString(), any(Object[].class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void dynamicQuery() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String tableName = "test_table"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<String> fields = Arrays.asList("id", "name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> conditions = Map.of("id", 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String orderBy = "id DESC"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Integer limit = 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Map<String, Object>> mockResult = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockResult.add(Map.of("id", 1, "name", "test_name")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockResult); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Map<String, Object>> result = dynamicModelService.dynamicQuery(tableName, fields, conditions, orderBy, limit); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(1, result.size()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals("test_name", result.get(0).get("name")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(namedParameterJdbcTemplate, times(1)).queryForList(anyString(), anyMap()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void dynamicCount() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String tableName = "test_table"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> conditions = Map.of("id", 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Map<String, Object>> mockResult = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockResult.add(Map.of("count", 5L)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockResult); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Map<String, Object>> result = dynamicModelService.dynamicCount(tableName, conditions); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(1, result.size()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(5L, result.get(0).get("count")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(namedParameterJdbcTemplate, times(1)).queryForList(anyString(), anyMap()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void count() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String tableName = "test_table"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> conditions = Map.of("id", 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Map<String, Object>> mockResult = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockResult.add(Map.of("count", 10L)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockResult); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Long result = dynamicModelService.count(tableName, conditions); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(10L, result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(namedParameterJdbcTemplate, times(1)).queryForList(anyString(), anyMap()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void queryWithPage() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DynamicQuery dto = new DynamicQuery(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setFields(Arrays.asList("id", "name")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setParams(Map.of("id", 1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setOrderBy("id DESC"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setCurrentPage(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setPageSize(10); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Map<String, Object>> mockData = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockData.add(Map.of("id", 1, "name", "test_name")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockData); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(List.of(Map.of("count", 1L))); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> result = dynamicModelService.queryWithPage(dto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertTrue((Boolean) result.get("success")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(1L, result.get("total")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(1, ((List<?>) result.get("data")).size()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(namedParameterJdbcTemplate, times(2)).queryForList(anyString(), anyMap()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+187
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Both Use sequential stubbing (order must match the production call order) or distinguish by SQL: ♻️ Proposed fix- when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(mockData);
- when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(List.of(Map.of("count", 1L)));
+ when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap()))
+ .thenReturn(mockData) // first call: data page
+ .thenReturn(List.of(Map.of("count", 1L))); // second call: total countConfirm the actual call order in 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void createData() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DynamicInsert dataDto = new DynamicInsert(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dataDto.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dataDto.setParams(Map.of("name", "test")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(loginUserContext.getLoginUserId()).thenReturn("1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(jdbcTemplate.update(any(PreparedStatementCreator.class), any(KeyHolder.class))).thenAnswer(invocation -> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| KeyHolder keyHolder = invocation.getArgument(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| keyHolder.getKeyList().add(Map.of("GENERATED_KEY", 1L)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> result = dynamicModelService.createData(dataDto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(1L, result.get("id")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any(KeyHolder.class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void getDataById() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String modelId = "test_table"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Long id = 1L; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Map<String, Object>> mockResult = new ArrayList<>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mockResult.add(Map.of("id", 1, "name", "test_name")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(jdbcTemplate.queryForList(anyString(), Optional.ofNullable(any()))).thenReturn(mockResult); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> result = dynamicModelService.getDataById(modelId, id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals("test_name", result.get("name")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).queryForList(anyString(), Optional.ofNullable(any())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+238
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
rg -nP -C2 'jdbcTemplate\.(queryForList|update)\s*\(' base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.javaRepository: opentiny/tiny-engine-backend-java Length of output: 1355 🏁 Script executed: cat -n base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java | sed -n '230,350p'Repository: opentiny/tiny-engine-backend-java Length of output: 4583 🏁 Script executed: cat -n base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.java | sed -n '350,360p'Repository: opentiny/tiny-engine-backend-java Length of output: 341 🏁 Script executed: rg -n 'import.*jdbcTemplate|import.*JdbcTemplate' base/src/test/java/com/tinyengine/it/dynamic/service/DynamicModelServiceTest.javaRepository: opentiny/tiny-engine-backend-java Length of output: 209 🏁 Script executed: rg -n -A10 'public.*getDataById|public.*deleteDataById' base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.java | head -60Repository: opentiny/tiny-engine-backend-java Length of output: 876 🏁 Script executed: cat -n base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.java | sed -n '640,645p'Repository: opentiny/tiny-engine-backend-java Length of output: 370 🏁 Script executed: rg -n 'queryForList|\.update\(' base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.java | grep -E '\.toArray|Object\[\]'Repository: opentiny/tiny-engine-backend-java Length of output: 206 🏁 Script executed: rg -n -B2 'jdbcTemplate\.(queryForList|update)' base/src/main/java/com/tinyengine/it/dynamic/service/DynamicModelService.javaRepository: opentiny/tiny-engine-backend-java Length of output: 1017 🏁 Script executed: python3 << 'EOF'
# Let's trace what the actual parameter types are in the production code
production_calls = {
"line_586": "queryForList(sql, id)", # id is Long
"line_642": "update(sql, id)", # id is Long
"line_169": "update(sql, values.toArray())", # Object[]
"line_623": "update(sql.toString(), params.toArray())", # Object[]
}
test_stubs = {
"lines_238_246": "queryForList(anyString(), Optional.ofNullable(any()))",
"lines_275_283": "update(anyString(), Optional.ofNullable(any()))",
"lines_349_353": "update(anyString(), Optional.ofNullable(any()))",
}
print("Production code parameter types:")
print("- queryForList(String, Long) - matches test at lines 238, 246")
print("- update(String, Long) - matches test at lines 275, 283, 349, 353")
print("- update(String, Object[]) - different overload")
print()
print("Test stub matcher issues:")
print("- Optional.ofNullable(any()) is INVALID matcher syntax")
print("- Should be any() for single parameter (Long)")
print("- Should be any(Object[].class) for array parameter")
EOFRepository: opentiny/tiny-engine-backend-java Length of output: 465 Fix invalid Mockito matcher usage: replace
Correct fixes:
Example: - when(jdbcTemplate.queryForList(anyString(), Optional.ofNullable(any()))).thenReturn(mockResult);
+ when(jdbcTemplate.queryForList(anyString(), any())).thenReturn(mockResult);
...
- verify(jdbcTemplate, times(1)).update(anyString(), Optional.ofNullable(any())).thenReturn(1);
+ verify(jdbcTemplate, times(1)).update(anyString(), any());Note: The method calls at lines 169 and 623 in production use 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void updateDateById() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DynamicUpdate dto = new DynamicUpdate(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setParams(Map.of("id", 1)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setData(Map.of("name", "updated_name")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(jdbcTemplate.update(anyString(), any(Object[].class))).thenReturn(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> result = dynamicModelService.updateDateById(dto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(1, result.get("rowsAffected")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).update(anyString(), any(Object[].class)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void deleteDataById() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DynamicDelete dto = new DynamicDelete(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setId(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(jdbcTemplate.update(anyString(), Optional.ofNullable(any()))).thenReturn(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> result = dynamicModelService.deleteDataById(dto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(1, result.get("rowsAffected")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).update(anyString(), Optional.ofNullable(any())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void testCreateDynamicTable() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Model model = new Model(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ParametersDto parametersDto = new ParametersDto(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setProp("name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setType("String"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setRequired(true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setDefaultValue("1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parametersDto.setDescription("1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model.setParameters(Collections.singletonList(parametersDto)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doNothing().when(jdbcTemplate).execute(anyString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertDoesNotThrow(() -> dynamicModelService.createDynamicTable(model)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).execute(anyString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void testDropDynamicTable() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Model model = new Model(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| model.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| doNothing().when(jdbcTemplate).execute(anyString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertDoesNotThrow(() -> dynamicModelService.dropDynamicTable(model)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).execute(anyString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void testDynamicQuery() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| String tableName = "test_table"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<String> fields = Arrays.asList("id", "name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> conditions = Map.of("id", 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(namedParameterJdbcTemplate.queryForList(anyString(), anyMap())).thenReturn(new ArrayList<>()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List<Map<String, Object>> result = dynamicModelService.dynamicQuery(tableName, fields, conditions, null, null); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(namedParameterJdbcTemplate, times(1)).queryForList(anyString(), anyMap()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void testCreateData() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DynamicInsert dataDto = new DynamicInsert(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dataDto.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dataDto.setParams(Map.of("name", "test")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(loginUserContext.getLoginUserId()).thenReturn("1"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(jdbcTemplate.update(any(), any(PreparedStatementCreator.class), any())).thenReturn(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> result = dynamicModelService.createData(dataDto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertNotNull(result); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).update(any(PreparedStatementCreator.class), any()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+329
to
+341
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Line 336 stubs This whole 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void testDeleteDataById() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DynamicDelete dto = new DynamicDelete(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setNameEn("test_table"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| dto.setId(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| when(jdbcTemplate.update(anyString(), Optional.ofNullable(any()))).thenReturn(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Map<String, Object> result = dynamicModelService.deleteDataById(dto); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assertEquals(1, result.get("rowsAffected")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| verify(jdbcTemplate, times(1)).update(anyString(), Optional.ofNullable(any())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant
openMockscall and unnecessaryReflectUtilusage.MockitoAnnotations.openMocks(this)is invoked twice; the second call creates a new set of mocks that are then discarded, and leaks the firstAutoCloseable. Keep one call (and ideally close it in@AfterEach, or switch to@ExtendWith(MockitoExtension.class)).DynamicModelServiceuses Lombok@RequiredArgsConstructoroverfinalfields (seeDynamicModelService.java:32-39), so@InjectMocksalready performs constructor injection with the three mocks. TheReflectUtil.setFieldValue(...)calls are redundant, and if the constructor injection ever silently fails (e.g. a mock is unnamed), reflection will mask that failure.♻️ Proposed simplification
📝 Committable suggestion
🤖 Prompt for AI Agents