Skip to content

Commit

Permalink
Fixed flakiness caused by Class.getDeclaredFields
Browse files Browse the repository at this point in the history
  • Loading branch information
SaaiVenkat committed Nov 4, 2023
1 parent 5e31029 commit 5195826
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 5195826

Please sign in to comment.