Skip to content

[tests] Various cleanups via Eclipse with extra hand holding #2822

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 11 commits into from
Feb 20, 2023
7 changes: 4 additions & 3 deletions src/test/java/org/apache/ibatis/binding/BindingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void shouldFindPostsInList() {
try (SqlSession session = sqlSessionFactory.openSession()) {
BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
List<Post> posts = mapper.findPostsInList(new ArrayList<Integer>() {
private static final long serialVersionUID = 1L;
{
add(1);
add(3);
Expand All @@ -122,7 +123,7 @@ void shouldFindPostsInList() {
void shouldFindPostsInArray() {
try (SqlSession session = sqlSessionFactory.openSession()) {
BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
Integer[] params = new Integer[] { 1, 3, 5 };
Integer[] params = { 1, 3, 5 };
List<Post> posts = mapper.findPostsInArray(params);
assertEquals(3, posts.size());
session.rollback();
Expand Down Expand Up @@ -430,6 +431,7 @@ void shouldSelectOneBlogAsMap() {
try (SqlSession session = sqlSessionFactory.openSession()) {
BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
Map<String, Object> blog = mapper.selectBlogAsMap(new HashMap<String, Object>() {
private static final long serialVersionUID = 1L;
{
put("id", 1);
}
Expand Down Expand Up @@ -588,8 +590,7 @@ void shouldCacheMapperMethod() throws Exception {
try (SqlSession session = sqlSessionFactory.openSession()) {

// Create another mapper instance with a method cache we can test against:
final MapperProxyFactory<BoundBlogMapper> mapperProxyFactory = new MapperProxyFactory<BoundBlogMapper>(
BoundBlogMapper.class);
final MapperProxyFactory<BoundBlogMapper> mapperProxyFactory = new MapperProxyFactory<>(BoundBlogMapper.class);
assertEquals(BoundBlogMapper.class, mapperProxyFactory.getMapperInterface());
final BoundBlogMapper mapper = mapperProxyFactory.newInstance(session);
assertNotSame(mapper, mapperProxyFactory.newInstance(session));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.apache.ibatis.reflection.factory.DefaultObjectFactory;

public class ExampleObjectFactory extends DefaultObjectFactory {
private static final long serialVersionUID = 1L;
private Properties properties;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void shouldConditionallyDefault() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE CATEGORY = 'DEFAULT'";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"),
new ChooseSqlNode(new ArrayList<SqlNode>() {
private static final long serialVersionUID = 1L;
{
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = ?")), "false"));
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = 'NONE'")), "false"));
Expand All @@ -101,6 +102,7 @@ void shouldConditionallyChooseFirst() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE CATEGORY = ?";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"),
new ChooseSqlNode(new ArrayList<SqlNode>() {
private static final long serialVersionUID = 1L;
{
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = ?")), "true"));
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = 'NONE'")), "false"));
Expand All @@ -115,6 +117,7 @@ void shouldConditionallyChooseSecond() throws Exception {
final String expected = "SELECT * FROM BLOG WHERE CATEGORY = 'NONE'";
DynamicSqlSource source = createDynamicSqlSource(new TextSqlNode("SELECT * FROM BLOG"),
new ChooseSqlNode(new ArrayList<SqlNode>() {
private static final long serialVersionUID = 1L;
{
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = ?")), "false"));
add(new IfSqlNode(mixedContents(new TextSqlNode("WHERE CATEGORY = 'NONE'")), "true"));
Expand Down Expand Up @@ -261,7 +264,8 @@ void shouldTrimNoSetClause() throws Exception {

@Test
void shouldIterateOnceForEachItemInCollection() throws Exception {
final HashMap<String, String[]> parameterObject = new HashMap<String, String[]>() {
final HashMap<String, String[]> parameterObject = new HashMap<>() {
private static final long serialVersionUID = 1L;
{
put("array", new String[] { "one", "two", "three" });
}
Expand All @@ -280,7 +284,8 @@ void shouldIterateOnceForEachItemInCollection() throws Exception {

@Test
void shouldHandleOgnlExpression() throws Exception {
final HashMap<String, String> parameterObject = new HashMap<String, String>() {
final HashMap<String, String> parameterObject = new HashMap<>() {
private static final long serialVersionUID = 1L;
{
put("name", "Steve");
}
Expand All @@ -294,7 +299,8 @@ void shouldHandleOgnlExpression() throws Exception {

@Test
void shouldSkipForEachWhenCollectionIsEmpty() throws Exception {
final HashMap<String, Integer[]> parameterObject = new HashMap<String, Integer[]>() {
final HashMap<String, Integer[]> parameterObject = new HashMap<>() {
private static final long serialVersionUID = 1L;
{
put("array", new Integer[] {});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class Bean {

@Test
void shouldIterateOverIterable() {
final HashMap<String, String[]> parameterObject = new HashMap<String, String[]>() {
final HashMap<String, String[]> parameterObject = new HashMap<>() {
private static final long serialVersionUID = 1L;
{
put("array", new String[] { "1", "2", "3" });
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/apache/ibatis/cache/CacheKeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ void shouldDemonstrateEmptyAndNullKeysAreEqual() {

@Test
void shouldTestCacheKeysWithBinaryArrays() {
byte[] array1 = new byte[] { 1 };
byte[] array2 = new byte[] { 1 };
byte[] array1 = { 1 };
byte[] array2 = { 1 };
CacheKey key1 = new CacheKey(new Object[] { array1 });
CacheKey key2 = new CacheKey(new Object[] { array2 });
assertEquals(key1, key2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void throwExceptionWhenTryingToCacheNonSerializableObject() {
}

static class CachingObject implements Serializable {
private static final long serialVersionUID = 1L;
int x;

public CachingObject(int x) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/ibatis/cache/SoftCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void shouldDemonstrateObjectsBeingCollectedAsNeeded() {
byte[] array = new byte[5001]; // waste a bunch of memory
array[5000] = 1;
cache.putObject(i, array);
Object value = cache.getObject(i);
cache.getObject(i);
if (cache.getSize() < i + 1) {
// System.out.println("Cache exceeded with " + (i + 1) + " entries.");
break;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/apache/ibatis/cache/SuperCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void shouldDemonstrate5LevelSuperCacheHandlesLotsOfEntriesWithoutCrashing() {
cache.putObject(i, i);
((TransactionalCache) cache).commit();
Object o = cache.getObject(i);
assertTrue(o == null || i == ((Integer) o));
assertTrue(o == null || i == (Integer) o);
}
assertTrue(cache.getSize() < N);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ void shouldCloseImmediatelyIfResultSetIsClosed() throws Exception {
}
}

@SuppressWarnings("serial")
private MappedStatement getNestedAndOrderedMappedStatement() {
final Configuration config = new Configuration();
final TypeHandlerRegistry registry = config.getTypeHandlerRegistry();

ResultMap nestedResultMap = new ResultMap.Builder(config, "roleMap", HashMap.class, new ArrayList<ResultMapping>() {
private static final long serialVersionUID = 1L;
{
add(new ResultMapping.Builder(config, "role", "role", registry.getTypeHandler(String.class)).build());
}
Expand All @@ -113,8 +113,10 @@ private MappedStatement getNestedAndOrderedMappedStatement() {

return new MappedStatement.Builder(config, "selectPerson", new StaticSqlSource(config, "select person..."),
SqlCommandType.SELECT).resultMaps(new ArrayList<ResultMap>() {
private static final long serialVersionUID = 1L;
{
add(new ResultMap.Builder(config, "personMap", HashMap.class, new ArrayList<ResultMapping>() {
private static final long serialVersionUID = 1L;
{
add(new ResultMapping.Builder(config, "id", "id", registry.getTypeHandler(Integer.class)).build());
add(new ResultMapping.Builder(config, "roles").nestedResultMapId("roleMap").build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void shouldRetrieveDataSourceFromJNDI() {
createJndiDataSource();
JndiDataSourceFactory factory = new JndiDataSourceFactory();
factory.setProperties(new Properties() {
private static final long serialVersionUID = 1L;
{
setProperty(JndiDataSourceFactory.ENV_PREFIX + Context.INITIAL_CONTEXT_FACTORY, TEST_INITIAL_CONTEXT_FACTORY);
setProperty(JndiDataSourceFactory.INITIAL_CONTEXT, TEST_INITIAL_CONTEXT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ class UnpooledDataSourceTest {
@Test
void shouldNotRegisterTheSameDriverMultipleTimes() throws Exception {
// https://github.com/mybatis/old-google-code-issues/issues/430
UnpooledDataSource dataSource = null;
dataSource = new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:multipledrivers", "sa", "");
UnpooledDataSource dataSource = new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:multipledrivers",
"sa", "");
dataSource.getConnection().close();
int before = countRegisteredDrivers();
dataSource = new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:multipledrivers", "sa", "");
Expand All @@ -44,12 +44,10 @@ void shouldNotRegisterTheSameDriverMultipleTimes() throws Exception {
@Test
void shouldRegisterDynamicallyLoadedDriver() throws Exception {
int before = countRegisteredDrivers();
ClassLoader driverClassLoader = null;
UnpooledDataSource dataSource = null;
driverClassLoader = new URLClassLoader(
ClassLoader driverClassLoader = new URLClassLoader(
new URL[] { new URL("jar:file:/PATH_TO/mysql-connector-java-5.1.25.jar!/") });
dataSource = new UnpooledDataSource(driverClassLoader, "com.mysql.jdbc.Driver", "jdbc:mysql://127.0.0.1/test",
"root", "");
UnpooledDataSource dataSource = new UnpooledDataSource(driverClassLoader, "com.mysql.jdbc.Driver",
"jdbc:mysql://127.0.0.1/test", "root", "");
dataSource.getConnection().close();
assertEquals(before + 1, countRegisteredDrivers());
driverClassLoader = new URLClassLoader(
Expand Down
17 changes: 5 additions & 12 deletions src/test/java/org/apache/ibatis/domain/blog/Author.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

public class Author implements Serializable {

private static final long serialVersionUID = 1L;
protected int id;
protected String username;
protected String password;
Expand Down Expand Up @@ -102,16 +103,9 @@ public boolean equals(Object o) {

Author author = (Author) o;

if (id != author.id) {
return false;
}
if (bio != null ? !bio.equals(author.bio) : author.bio != null) {
return false;
}
if (email != null ? !email.equals(author.email) : author.email != null) {
return false;
}
if (password != null ? !password.equals(author.password) : author.password != 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) {
Expand All @@ -133,8 +127,7 @@ public int hashCode() {
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (bio != null ? bio.hashCode() : 0);
result = 31 * result + (favouriteSection != null ? favouriteSection.hashCode() : 0);
return result;
return 31 * result + (favouriteSection != null ? favouriteSection.hashCode() : 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.Serializable;

public class ComplexImmutableAuthor implements Serializable {
private static final long serialVersionUID = 1L;
private final ComplexImmutableAuthorId theComplexImmutableAuthorId;
protected final String bio;
protected final Section favouriteSection;
Expand Down Expand Up @@ -51,14 +52,9 @@ public boolean equals(Object o) {

final ComplexImmutableAuthor that = (ComplexImmutableAuthor) o;

if (bio != null ? !bio.equals(that.bio) : that.bio != null) {
return false;
}
if (favouriteSection != that.favouriteSection) {
return false;
}
if (theComplexImmutableAuthorId != null ? !theComplexImmutableAuthorId.equals(that.theComplexImmutableAuthorId)
: that.theComplexImmutableAuthorId != null) {
if ((bio != null ? !bio.equals(that.bio) : that.bio != null) || (favouriteSection != that.favouriteSection)
|| (theComplexImmutableAuthorId != null ? !theComplexImmutableAuthorId.equals(that.theComplexImmutableAuthorId)
: that.theComplexImmutableAuthorId != null)) {
return false;
}

Expand All @@ -69,7 +65,6 @@ public boolean equals(Object o) {
public int hashCode() {
int myresult = theComplexImmutableAuthorId != null ? theComplexImmutableAuthorId.hashCode() : 0;
myresult = 31 * myresult + (bio != null ? bio.hashCode() : 0);
myresult = 31 * myresult + (favouriteSection != null ? favouriteSection.hashCode() : 0);
return myresult;
return 31 * myresult + (favouriteSection != null ? favouriteSection.hashCode() : 0);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 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 @@ -55,16 +55,9 @@ public boolean equals(Object o) {

final ComplexImmutableAuthorId that = (ComplexImmutableAuthorId) o;

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

Expand All @@ -76,7 +69,6 @@ public int hashCode() {
int myresult = id;
myresult = 31 * myresult + (email != null ? email.hashCode() : 0);
myresult = 31 * myresult + (username != null ? username.hashCode() : 0);
myresult = 31 * myresult + (password != null ? password.hashCode() : 0);
return myresult;
return 31 * myresult + (password != null ? password.hashCode() : 0);
}
}
17 changes: 5 additions & 12 deletions src/test/java/org/apache/ibatis/domain/blog/ImmutableAuthor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.Serializable;

public class ImmutableAuthor implements Serializable {
private static final long serialVersionUID = 1L;
protected final int id;
protected final String username;
protected final String password;
Expand Down Expand Up @@ -69,16 +70,9 @@ public boolean equals(Object o) {

Author author = (Author) o;

if (id != author.id) {
return false;
}
if (bio != null ? !bio.equals(author.bio) : author.bio != null) {
return false;
}
if (email != null ? !email.equals(author.email) : author.email != null) {
return false;
}
if (password != null ? !password.equals(author.password) : author.password != 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) {
Expand All @@ -100,8 +94,7 @@ public int hashCode() {
result = 31 * result + (password != null ? password.hashCode() : 0);
result = 31 * result + (email != null ? email.hashCode() : 0);
result = 31 * result + (bio != null ? bio.hashCode() : 0);
result = 31 * result + (favouriteSection != null ? favouriteSection.hashCode() : 0);
return result;
return 31 * result + (favouriteSection != null ? favouriteSection.hashCode() : 0);
}

@Override
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/org/apache/ibatis/domain/blog/PostLite.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ public boolean equals(Object o) {

final PostLite that = (PostLite) o;

if (blogId != that.blogId) {
return false;
}
if (theId != null ? !theId.equals(that.theId) : that.theId != null) {
if ((blogId != that.blogId) || (theId != null ? !theId.equals(that.theId) : that.theId != null)) {
return false;
}

Expand All @@ -67,7 +64,6 @@ public boolean equals(Object o) {
@Override
public int hashCode() {
int myresult = theId != null ? theId.hashCode() : 0;
myresult = 31 * myresult + blogId;
return myresult;
return 31 * myresult + blogId;
}
}
5 changes: 2 additions & 3 deletions src/test/java/org/apache/ibatis/domain/jpetstore/Cart.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ public Item removeItemById(String itemId) {
CartItem cartItem = itemMap.remove(itemId);
if (cartItem == null) {
return null;
} else {
itemList.remove(cartItem);
return cartItem.getItem();
}
itemList.remove(cartItem);
return cartItem.getItem();
}

public void incrementQuantityByItemId(String itemId) {
Expand Down
Loading