Skip to content

Commit

Permalink
Refactor test code (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
nakamura-to authored Dec 28, 2024
2 parents 1fc08fb + a1da735 commit a090a27
Show file tree
Hide file tree
Showing 78 changed files with 538 additions and 648 deletions.
3 changes: 2 additions & 1 deletion doma-core/src/test/java/example/entity/Dept.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package example.entity;

import java.io.Serial;
import java.io.Serializable;
import org.seasar.doma.Entity;
import org.seasar.doma.Id;
Expand All @@ -10,7 +11,7 @@
@Table(catalog = "CATA", quote = true)
public class Dept implements Serializable {

private static final long serialVersionUID = 1;
@Serial private static final long serialVersionUID = 1;

@Id Integer id;

Expand Down
3 changes: 2 additions & 1 deletion doma-core/src/test/java/example/entity/Emp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package example.entity;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import org.seasar.doma.Entity;
Expand All @@ -13,7 +14,7 @@
@Table(catalog = "CATA", quote = true)
public class Emp implements Serializable {

private static final long serialVersionUID = -6511179565163144602L;
@Serial private static final long serialVersionUID = -6511179565163144602L;

@Id Integer id;

Expand Down
3 changes: 2 additions & 1 deletion doma-core/src/test/java/example/entity/IdGeneratedEmp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package example.entity;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import org.seasar.doma.Entity;
Expand All @@ -15,7 +16,7 @@
@Table(catalog = "CATA", quote = true)
public class IdGeneratedEmp implements Serializable {

private static final long serialVersionUID = -6511179565163144602L;
@Serial private static final long serialVersionUID = -6511179565163144602L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down
3 changes: 2 additions & 1 deletion doma-core/src/test/java/example/entity/ImmutableEmp.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package example.entity;

import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import org.seasar.doma.Entity;
Expand All @@ -10,7 +11,7 @@
@Entity(naming = NamingType.SNAKE_UPPER_CASE, immutable = true)
public class ImmutableEmp implements Serializable {

private static final long serialVersionUID = 1L;
@Serial private static final long serialVersionUID = 1L;

@Id final Integer id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void testHandle() throws Exception {
EntityIterationHandler<Emp, Integer> handler =
new EntityIterationHandler<>(
_Emp.getSingletonInternal(),
new IterationCallback<Emp, Integer>() {
new IterationCallback<>() {

private int count;

Expand Down Expand Up @@ -87,7 +87,7 @@ public void testHandle_exits() throws Exception {
EntityIterationHandler<Emp, Integer> handler =
new EntityIterationHandler<>(
_Emp.getSingletonInternal(),
new IterationCallback<Emp, Integer>() {
new IterationCallback<>() {

private int count;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ public void testReadSql_sqlBlock_createTrigger() {

@Override
protected BufferedReader createBufferedReader() {
String script = "create trigger hoge begin aaa; end\n" + "go\n";
String script =
"""
create trigger hoge begin aaa; end
go
""";
StringReader reader = new StringReader(script);
return new BufferedReader(reader);
}
Expand All @@ -106,7 +110,11 @@ public void testReadSql_notSqlBlock() {
new ScriptReader(query) {
@Override
protected BufferedReader createBufferedReader() {
String script = "start aaa; end\n" + "go\n";
String script =
"""
start aaa; end
go
""";
StringReader reader = new StringReader(script);
return new BufferedReader(reader);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,6 @@ public QueryImplementors getQueryImplementors() {
return queryImplementors;
}

@Override
public SqlLogType getExceptionSqlLogType() {
return SqlLogType.FORMATTED;
}

@Override
public int getFetchSize() {
return 0;
}

@Override
public int getMaxRows() {
return 0;
}

@Override
public int getQueryTimeout() {
return 0;
}

@Override
public int getBatchSize() {
return 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import example.domain.InternationalPhoneNumber;
import example.domain.PhoneNumber;
Expand Down Expand Up @@ -121,8 +121,8 @@ public void testWrapBasic_optional() {
assertNotNull(supplier);

Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof Optional);
assertTrue(scalar.getAsNonOptional() instanceof Integer);
assertInstanceOf(Optional.class, scalar.get());
assertInstanceOf(Integer.class, scalar.getAsNonOptional());
Optional<Integer> optional = (Optional<Integer>) scalar.get();
assertEquals(10, optional.get());

Expand All @@ -138,7 +138,7 @@ public void testWrapBasic_optional_null() {
assertNotNull(supplier);

Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof Optional);
assertInstanceOf(Optional.class, scalar.get());
assertNull(scalar.getAsNonOptional());
Optional<Integer> optional = (Optional<Integer>) scalar.get();
assertFalse(optional.isPresent());
Expand Down Expand Up @@ -181,7 +181,7 @@ public void testWrapEnum_optional() {
assertNotNull(supplier);

Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof Optional);
assertInstanceOf(Optional.class, scalar.get());
Optional<MyEnum> optional = (Optional<MyEnum>) scalar.get();
assertEquals(MyEnum.AAA, optional.get());

Expand All @@ -197,7 +197,7 @@ public void testWrapEnum_optional_null() {
assertNotNull(supplier);

Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof Optional);
assertInstanceOf(Optional.class, scalar.get());
Optional<MyEnum> optional = (Optional<MyEnum>) scalar.get();
assertFalse(optional.isPresent());

Expand Down Expand Up @@ -230,7 +230,7 @@ public void testWrapDomain_subclass() {
assertNotNull(supplier);

Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof InternationalPhoneNumber);
assertInstanceOf(InternationalPhoneNumber.class, scalar.get());

Wrapper<?> wrapper = scalar.getWrapper();
assertEquals(StringWrapper.class, wrapper.getClass());
Expand All @@ -243,8 +243,8 @@ public void testWrapDomain_null() {
assertNotNull(supplier);

Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof PhoneNumber);
assertTrue(scalar.getAsNonOptional() instanceof PhoneNumber);
assertInstanceOf(PhoneNumber.class, scalar.get());
assertInstanceOf(PhoneNumber.class, scalar.getAsNonOptional());
PhoneNumber phoneNumber = (PhoneNumber) scalar.get();
assertNull(phoneNumber.getValue());

Expand All @@ -262,8 +262,8 @@ public void testWrapDomain_option() {
assertNotNull(supplier);

Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof Optional);
assertTrue(scalar.getAsNonOptional() instanceof PhoneNumber);
assertInstanceOf(Optional.class, scalar.get());
assertInstanceOf(PhoneNumber.class, scalar.getAsNonOptional());
Optional<PhoneNumber> optional = (Optional<PhoneNumber>) scalar.get();
assertEquals(phoneNumber, optional.get());

Expand All @@ -279,7 +279,7 @@ public void testWrapDomain_option_null() {
assertNotNull(supplier);

Scalar<?, ?> scalar = supplier.get();
assertTrue(scalar.get() instanceof Optional);
assertInstanceOf(Optional.class, scalar.get());
assertNull(scalar.getAsNonOptional());
Optional<PhoneNumber> optional = (Optional<PhoneNumber>) scalar.get();
assertFalse(optional.isPresent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class SqlTokenizerTest {

@BeforeEach
protected void setUp() {
lineSeparator = System.getProperty("line.separator");
lineSeparator = System.lineSeparator();
System.setProperty("line.separator", "\r\n");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.seasar.doma.internal.util;

import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.*;

import java.util.Arrays;
Expand All @@ -13,7 +12,7 @@ class ZipTest {
void stream() {
List<String> a = Arrays.asList("a", "b", "c");
List<Integer> b = Arrays.asList(1, 2, 3, 4, 5);
List<Pair<String, Integer>> result = Zip.stream(a, b).collect(toList());
List<Pair<String, Integer>> result = Zip.stream(a, b).toList();
assertEquals(3, result.size());
assertEquals("a", result.get(0).fst);
assertEquals(Integer.valueOf(1), result.get(0).snd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,17 @@ public void testExecutor() {
@Test
public void testExecutorByMap() {
List<LinkedHashMap<String, Object>> employees =
new ArrayList<LinkedHashMap<String, Object>>() {
new ArrayList<>() {
{
add(
new LinkedHashMap<String, Object>() {
new LinkedHashMap<>() {
{
put("name", "SMITH");
put("salary", 500);
}
});
add(
new LinkedHashMap<String, Object>() {
new LinkedHashMap<>() {
{
put("name", "ALLEN");
put("salary", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testLiteral() {
}

@Test
public void testParams() throws Exception {
public void testParams() {
DeleteBuilder builder = DeleteBuilder.newInstance(new MockConfig());
builder.sql("delete from Emp");
builder.sql("where");
Expand Down Expand Up @@ -84,7 +84,7 @@ public void testParams() throws Exception {
}

@Test
public void testParams_empty() throws Exception {
public void testParams_empty() {
DeleteBuilder builder = DeleteBuilder.newInstance(new MockConfig());
builder.sql("delete from Emp");
builder.sql("where");
Expand All @@ -102,7 +102,7 @@ public void testParams_empty() throws Exception {
}

@Test
public void testLiterals() throws Exception {
public void testLiterals() {
DeleteBuilder builder = DeleteBuilder.newInstance(new MockConfig());
builder.sql("delete from Emp");
builder.sql("where");
Expand All @@ -124,7 +124,7 @@ public void testLiterals() throws Exception {
}

@Test
public void testLiterals_empty() throws Exception {
public void testLiterals_empty() {
DeleteBuilder builder = DeleteBuilder.newInstance(new MockConfig());
builder.sql("delete from Emp");
builder.sql("where");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testLiteral() {
}

@Test
public void testParams() throws Exception {
public void testParams() {
InsertBuilder builder = InsertBuilder.newInstance(new MockConfig());
builder.sql("insert into TmpEmp");
builder.sql("(name, salary)");
Expand Down Expand Up @@ -86,7 +86,7 @@ public void testParams() throws Exception {
}

@Test
public void testParams_empty() throws Exception {
public void testParams_empty() {
InsertBuilder builder = InsertBuilder.newInstance(new MockConfig());
builder.sql("insert into TmpEmp");
builder.sql("(name, salary)");
Expand All @@ -112,7 +112,7 @@ public void testParams_empty() throws Exception {
}

@Test
public void testLiterals() throws Exception {
public void testLiterals() {
InsertBuilder builder = InsertBuilder.newInstance(new MockConfig());
builder.sql("insert into TmpEmp");
builder.sql("(name, salary)");
Expand All @@ -138,7 +138,7 @@ public void testLiterals() throws Exception {
}

@Test
public void testLiterals_empty() throws Exception {
public void testLiterals_empty() {
InsertBuilder builder = InsertBuilder.newInstance(new MockConfig());
builder.sql("insert into TmpEmp");
builder.sql("(name, salary)");
Expand Down
Loading

0 comments on commit a090a27

Please sign in to comment.