Skip to content

Commit 04b2658

Browse files
authored
Merge pull request mybatis#3345 from hazendaz/pom-cleanup
Newer java style in tests
2 parents 7788c29 + e577e83 commit 04b2658

File tree

10 files changed

+60
-67
lines changed

10 files changed

+60
-67
lines changed

src/test/java/org/apache/ibatis/autoconstructor/BadSubject.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2022 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,7 @@ public BadSubject(final int id, final String name, final int age, final Height h
3030
this.weight = weight == null ? 0 : weight;
3131
}
3232

33-
private class Height {
33+
private static class Height {
3434

3535
}
3636
}

src/test/java/org/apache/ibatis/builder/XmlMapperBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ void errorResultMapLocation() throws Exception {
221221
builder.parse();
222222
String resultMapName = "java.lang.String";
223223
// namespace + "." + id
224-
String statementId = "org.mybatis.spring.ErrorProblemMapper" + "." + "findProblemResultMapTest";
224+
String statementId = "org.mybatis.spring.ErrorProblemMapper.findProblemResultMapTest";
225225
// same as MapperBuilderAssistant.getStatementResultMaps Exception message
226226
String message = "Could not find result map '" + resultMapName + "' referenced from '" + statementId + "'";
227227
IncompleteElementException exception = Assertions.assertThrows(IncompleteElementException.class,

src/test/java/org/apache/ibatis/domain/blog/Author.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,17 @@ public boolean equals(Object o) {
9797
if (this == o) {
9898
return true;
9999
}
100-
if (!(o instanceof Author)) {
100+
if (!(o instanceof Author author)) {
101101
return false;
102102
}
103103

104-
Author author = (Author) o;
105-
106-
if ((id != author.id) || (bio != null ? !bio.equals(author.bio) : author.bio != null)
104+
if (id != author.id || (bio != null ? !bio.equals(author.bio) : author.bio != null)
107105
|| (email != null ? !email.equals(author.email) : author.email != null)
108106
|| (password != null ? !password.equals(author.password) : author.password != null)) {
109107
return false;
110108
}
111-
if (username != null ? !username.equals(author.username) : author.username != null) {
112-
return false;
113-
}
114-
if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection)
115-
: author.favouriteSection != null) {
109+
if ((username != null ? !username.equals(author.username) : author.username != null) || (favouriteSection != null
110+
? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)) {
116111
return false;
117112
}
118113

src/test/java/org/apache/ibatis/domain/blog/ImmutableAuthor.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,17 @@ public boolean equals(Object o) {
6464
if (this == o) {
6565
return true;
6666
}
67-
if (!(o instanceof Author)) {
67+
if (!(o instanceof Author author)) {
6868
return false;
6969
}
7070

71-
Author author = (Author) o;
72-
73-
if ((id != author.id) || (bio != null ? !bio.equals(author.bio) : author.bio != null)
71+
if (id != author.id || (bio != null ? !bio.equals(author.bio) : author.bio != null)
7472
|| (email != null ? !email.equals(author.email) : author.email != null)
7573
|| (password != null ? !password.equals(author.password) : author.password != null)) {
7674
return false;
7775
}
78-
if (username != null ? !username.equals(author.username) : author.username != null) {
79-
return false;
80-
}
81-
if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection)
82-
: author.favouriteSection != null) {
76+
if ((username != null ? !username.equals(author.username) : author.username != null) || (favouriteSection != null
77+
? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)) {
8378
return false;
8479
}
8580

src/test/java/org/apache/ibatis/submitted/cglib_lazy_error/Person.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,12 +34,10 @@ public boolean equals(Object o) {
3434
if (this == o) {
3535
return true;
3636
}
37-
if (!(o instanceof Person)) {
37+
if (!(o instanceof Person person)) {
3838
return false;
3939
}
4040

41-
Person person = (Person) o;
42-
4341
if (id != null ? !id.equals(person.id) : person.id != null) {
4442
return false;
4543
}

src/test/java/org/apache/ibatis/submitted/extendresultmap/TestModel.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,14 +56,11 @@ public boolean equals(Object obj) {
5656
if (this == obj) {
5757
return true;
5858
}
59-
if ((obj == null) || (getClass() != obj.getClass())) {
59+
if (obj == null || getClass() != obj.getClass()) {
6060
return false;
6161
}
6262
TestModel other = (TestModel) obj;
63-
if (!Objects.equals(a, other.a)) {
64-
return false;
65-
}
66-
if (!Objects.equals(b, other.b)) {
63+
if (!Objects.equals(a, other.a) || !Objects.equals(b, other.b)) {
6764
return false;
6865
}
6966
return true;

src/test/java/org/apache/ibatis/submitted/language/VelocitySqlSourceBuilder.java

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,25 +97,39 @@ private ParameterMapping buildParameterMapping(String content) {
9797
for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {
9898
String name = entry.getKey();
9999
String value = entry.getValue();
100-
if ("javaType".equals(name)) {
101-
javaType = resolveClass(value);
102-
builder.javaType(javaType);
103-
} else if ("jdbcType".equals(name)) {
104-
builder.jdbcType(resolveJdbcType(value));
105-
} else if ("mode".equals(name)) {
106-
builder.mode(resolveParameterMode(value));
107-
} else if ("numericScale".equals(name)) {
108-
builder.numericScale(Integer.valueOf(value));
109-
} else if ("resultMap".equals(name)) {
110-
builder.resultMapId(value);
111-
} else if ("typeHandler".equals(name)) {
112-
typeHandlerAlias = value;
113-
} else if ("jdbcTypeName".equals(name)) {
114-
builder.jdbcTypeName(value);
115-
} else if ("property".equals(name)) {
116-
// Do Nothing
117-
} else if ("expression".equals(name)) {
118-
builder.expression(value);
100+
if (name != null) {
101+
switch (name) {
102+
case "javaType":
103+
javaType = resolveClass(value);
104+
builder.javaType(javaType);
105+
break;
106+
case "jdbcType":
107+
builder.jdbcType(resolveJdbcType(value));
108+
break;
109+
case "mode":
110+
builder.mode(resolveParameterMode(value));
111+
break;
112+
case "numericScale":
113+
builder.numericScale(Integer.valueOf(value));
114+
break;
115+
case "resultMap":
116+
builder.resultMapId(value);
117+
break;
118+
case "typeHandler":
119+
typeHandlerAlias = value;
120+
break;
121+
case "jdbcTypeName":
122+
builder.jdbcTypeName(value);
123+
break;
124+
case "property":
125+
break;
126+
case "expression":
127+
builder.expression(value);
128+
break;
129+
default:
130+
throw new BuilderException("An invalid property '" + name + "' was found in mapping @{" + content
131+
+ "}. Valid properties are " + parameterProperties);
132+
}
119133
} else {
120134
throw new BuilderException("An invalid property '" + name + "' was found in mapping @{" + content
121135
+ "}. Valid properties are " + parameterProperties);

src/test/java/org/apache/ibatis/submitted/nestedresulthandler_multiple_association/Binome.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -50,8 +50,7 @@ public int hashCode() {
5050

5151
@Override
5252
public boolean equals(final Object obj) {
53-
if (obj instanceof Binome<?, ?>) {
54-
Binome<?, ?> bin = (Binome<?, ?>) obj;
53+
if (obj instanceof Binome<?, ?> bin) {
5554
return one != null && one.equals(bin.getOne()) && two != null && two.equals(bin.getTwo());
5655
}
5756
return super.equals(obj);

src/test/java/org/apache/ibatis/submitted/sqlprovider/OurSqlBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -270,8 +270,7 @@ private Class<?> getEntityClass(ProviderContext providerContext) {
270270

271271
Type[] types = mapperClass.getGenericInterfaces();
272272
for (Type type : types) {
273-
if (type instanceof ParameterizedType) {
274-
ParameterizedType t = (ParameterizedType) type;
273+
if (type instanceof ParameterizedType t) {
275274
if (t.getRawType() == declaringClass || mapperClass.isAssignableFrom((Class<?>) t.getRawType())) {
276275
return (Class<?>) t.getActualTypeArguments()[0];
277276
}

src/test/java/org/apache/ibatis/submitted/sqlprovider/SqlProviderTest.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -710,16 +710,12 @@ public interface DefaultSqlProviderMapper {
710710
class SqlProvider {
711711

712712
public static String provideSql(ProviderContext c) {
713-
switch (c.getMapperMethod().getName()) {
714-
case "select":
715-
return "select name from foo where id = #{id}";
716-
case "insert":
717-
return "insert into foo (name) values(#{name})";
718-
case "update":
719-
return "update foo set name = #{name} where id = #{id}";
720-
default:
721-
return "delete from foo where id = #{id}";
722-
}
713+
return switch (c.getMapperMethod().getName()) {
714+
case "select" -> "select name from foo where id = #{id}";
715+
case "insert" -> "insert into foo (name) values(#{name})";
716+
case "update" -> "update foo set name = #{name} where id = #{id}";
717+
default -> "delete from foo where id = #{id}";
718+
};
723719
}
724720

725721
private SqlProvider() {

0 commit comments

Comments
 (0)