Skip to content

Newer java style in tests #3345

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

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,7 +30,7 @@ public BadSubject(final int id, final String name, final int age, final Height h
this.weight = weight == null ? 0 : weight;
}

private class Height {
private static class Height {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ void errorResultMapLocation() throws Exception {
builder.parse();
String resultMapName = "java.lang.String";
// namespace + "." + id
String statementId = "org.mybatis.spring.ErrorProblemMapper" + "." + "findProblemResultMapTest";
String statementId = "org.mybatis.spring.ErrorProblemMapper.findProblemResultMapTest";
// same as MapperBuilderAssistant.getStatementResultMaps Exception message
String message = "Could not find result map '" + resultMapName + "' referenced from '" + statementId + "'";
IncompleteElementException exception = Assertions.assertThrows(IncompleteElementException.class,
Expand Down
13 changes: 4 additions & 9 deletions src/test/java/org/apache/ibatis/domain/blog/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,17 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Author)) {
if (!(o instanceof Author author)) {
return false;
}

Author author = (Author) o;

if ((id != author.id) || (bio != null ? !bio.equals(author.bio) : author.bio != null)
if (id != author.id || (bio != null ? !bio.equals(author.bio) : author.bio != null)
|| (email != null ? !email.equals(author.email) : author.email != null)
|| (password != null ? !password.equals(author.password) : author.password != null)) {
return false;
}
if (username != null ? !username.equals(author.username) : author.username != null) {
return false;
}
if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection)
: author.favouriteSection != null) {
if ((username != null ? !username.equals(author.username) : author.username != null) || (favouriteSection != null
? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)) {
return false;
}

Expand Down
13 changes: 4 additions & 9 deletions src/test/java/org/apache/ibatis/domain/blog/ImmutableAuthor.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,17 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Author)) {
if (!(o instanceof Author author)) {
return false;
}

Author author = (Author) o;

if ((id != author.id) || (bio != null ? !bio.equals(author.bio) : author.bio != null)
if (id != author.id || (bio != null ? !bio.equals(author.bio) : author.bio != null)
|| (email != null ? !email.equals(author.email) : author.email != null)
|| (password != null ? !password.equals(author.password) : author.password != null)) {
return false;
}
if (username != null ? !username.equals(author.username) : author.username != null) {
return false;
}
if (favouriteSection != null ? !favouriteSection.equals(author.favouriteSection)
: author.favouriteSection != null) {
if ((username != null ? !username.equals(author.username) : author.username != null) || (favouriteSection != null
? !favouriteSection.equals(author.favouriteSection) : author.favouriteSection != null)) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,12 +34,10 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof Person)) {
if (!(o instanceof Person person)) {
return false;
}

Person person = (Person) o;

if (id != null ? !id.equals(person.id) : person.id != null) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -56,14 +56,11 @@ public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if ((obj == null) || (getClass() != obj.getClass())) {
if (obj == null || getClass() != obj.getClass()) {
return false;
}
TestModel other = (TestModel) obj;
if (!Objects.equals(a, other.a)) {
return false;
}
if (!Objects.equals(b, other.b)) {
if (!Objects.equals(a, other.a) || !Objects.equals(b, other.b)) {
return false;
}
return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -97,25 +97,39 @@ private ParameterMapping buildParameterMapping(String content) {
for (Map.Entry<String, String> entry : propertiesMap.entrySet()) {
String name = entry.getKey();
String value = entry.getValue();
if ("javaType".equals(name)) {
javaType = resolveClass(value);
builder.javaType(javaType);
} else if ("jdbcType".equals(name)) {
builder.jdbcType(resolveJdbcType(value));
} else if ("mode".equals(name)) {
builder.mode(resolveParameterMode(value));
} else if ("numericScale".equals(name)) {
builder.numericScale(Integer.valueOf(value));
} else if ("resultMap".equals(name)) {
builder.resultMapId(value);
} else if ("typeHandler".equals(name)) {
typeHandlerAlias = value;
} else if ("jdbcTypeName".equals(name)) {
builder.jdbcTypeName(value);
} else if ("property".equals(name)) {
// Do Nothing
} else if ("expression".equals(name)) {
builder.expression(value);
if (name != null) {
switch (name) {
case "javaType":
javaType = resolveClass(value);
builder.javaType(javaType);
break;
case "jdbcType":
builder.jdbcType(resolveJdbcType(value));
break;
case "mode":
builder.mode(resolveParameterMode(value));
break;
case "numericScale":
builder.numericScale(Integer.valueOf(value));
break;
case "resultMap":
builder.resultMapId(value);
break;
case "typeHandler":
typeHandlerAlias = value;
break;
case "jdbcTypeName":
builder.jdbcTypeName(value);
break;
case "property":
break;
case "expression":
builder.expression(value);
break;
default:
throw new BuilderException("An invalid property '" + name + "' was found in mapping @{" + content
+ "}. Valid properties are " + parameterProperties);
}
} else {
throw new BuilderException("An invalid property '" + name + "' was found in mapping @{" + content
+ "}. Valid properties are " + parameterProperties);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,8 +50,7 @@ public int hashCode() {

@Override
public boolean equals(final Object obj) {
if (obj instanceof Binome<?, ?>) {
Binome<?, ?> bin = (Binome<?, ?>) obj;
if (obj instanceof Binome<?, ?> bin) {
return one != null && one.equals(bin.getOne()) && two != null && two.equals(bin.getTwo());
}
return super.equals(obj);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2023 the original author or authors.
* Copyright 2009-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -270,8 +270,7 @@ private Class<?> getEntityClass(ProviderContext providerContext) {

Type[] types = mapperClass.getGenericInterfaces();
for (Type type : types) {
if (type instanceof ParameterizedType) {
ParameterizedType t = (ParameterizedType) type;
if (type instanceof ParameterizedType t) {
if (t.getRawType() == declaringClass || mapperClass.isAssignableFrom((Class<?>) t.getRawType())) {
return (Class<?>) t.getActualTypeArguments()[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,16 +710,12 @@ public interface DefaultSqlProviderMapper {
class SqlProvider {

public static String provideSql(ProviderContext c) {
switch (c.getMapperMethod().getName()) {
case "select":
return "select name from foo where id = #{id}";
case "insert":
return "insert into foo (name) values(#{name})";
case "update":
return "update foo set name = #{name} where id = #{id}";
default:
return "delete from foo where id = #{id}";
}
return switch (c.getMapperMethod().getName()) {
case "select" -> "select name from foo where id = #{id}";
case "insert" -> "insert into foo (name) values(#{name})";
case "update" -> "update foo set name = #{name} where id = #{id}";
default -> "delete from foo where id = #{id}";
};
}

private SqlProvider() {
Expand Down
Loading