Skip to content

Commit

Permalink
Merge pull request #896 from SaaiVenkat/fix-flaky-tests
Browse files Browse the repository at this point in the history
修复了`Class.getDeclaredFields()`返回的元素的不确定顺序引起的问题
  • Loading branch information
abel533 authored Apr 6, 2024
2 parents 0ca737b + 5195826 commit 9913d99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ private List<EntityField> _getFields(Class<?> entityClass, List<EntityField> fie
return fieldList;
}
Field[] fields = entityClass.getDeclaredFields();
Arrays.sort(fields, Comparator.comparing(Field::getName));
int index = 0;
for (int i = 0; i < fields.length; i++) {
Field field = fields[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,19 @@ public void test() {
sqlBuilder.append(SqlHelper.fromTable(entityClass, entityTable.getName()));
sqlBuilder.append(SqlHelper.whereAllIfColumns(entityClass, config.isNotEmpty()));
final String sql = sqlBuilder.toString();
Assert.assertEquals("SELECT id,user_name,address,state FROM user " +
Assert.assertEquals("SELECT address,id,state,user_name FROM user " +
"<where>" +
"<if test=\"id != null\"> AND id = #{id}</if>" +
"<if test=\"userName != null\"> AND user_name = #{userName}</if>" +
"<if test=\"address != null\"> AND address = #{address, typeHandler=tk.mybatis.mapper.mapperhelper.ComplexEntityTest$AddressHandler}</if>" +
"<if test=\"state != null\"> AND state = #{state}</if></where>", sql);
"<if test=\"id != null\"> AND id = #{id}</if>" +
"<if test=\"state != null\"> AND state = #{state}</if>" +
"<if test=\"userName != null\"> AND user_name = #{userName}</if></where>", sql);

final ResultMap resultMap = entityTable.getResultMap(configuration);
final List<ResultMapping> resultMappings = resultMap.getResultMappings();
final ResultMapping idMapping = resultMappings.get(0);
final ResultMapping userNameMapping = resultMappings.get(1);
final ResultMapping addressMapping = resultMappings.get(2);
final ResultMapping stateMapping = resultMappings.get(3);
final ResultMapping addressMapping = resultMappings.get(0);
final ResultMapping idMapping = resultMappings.get(1);
final ResultMapping stateMapping = resultMappings.get(2);
final ResultMapping userNameMapping = resultMappings.get(3);

Assert.assertEquals("id", idMapping.getColumn());
Assert.assertEquals("id", idMapping.getProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void testLogicDeleteSql() {
Assert.assertEquals(" AND is_valid = 1", notLogicDeletedColumn);

String updateSetColumns = SqlHelper.updateSetColumns(User.class, null, false, false);
Assert.assertEquals("<set>username = #{username},is_valid = 1,</set>", updateSetColumns);
Assert.assertEquals("<set>is_valid = 1,username = #{username},</set>", updateSetColumns);
}

}
Expand Down

0 comments on commit 9913d99

Please sign in to comment.