mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2716 - Refactor ScalarType interface to make use of default methods
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.text.TextException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -11,13 +10,12 @@ import java.time.Duration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ScalarTypeDurationTest {
|
||||
class ScalarTypeDurationTest {
|
||||
|
||||
ScalarTypeDuration type = new ScalarTypeDuration();
|
||||
|
||||
@Test
|
||||
public void testReadData() throws Exception {
|
||||
|
||||
void testReadData() throws Exception {
|
||||
Duration duration = Duration.ofSeconds(1234);
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
@@ -39,8 +37,7 @@ public class ScalarTypeDurationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToJdbcType() throws Exception {
|
||||
|
||||
void testToJdbcType() throws Exception {
|
||||
Duration duration = Duration.ofSeconds(1234);
|
||||
long seconds = duration.getSeconds();
|
||||
|
||||
@@ -52,8 +49,7 @@ public class ScalarTypeDurationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToBeanType() throws Exception {
|
||||
|
||||
void testToBeanType() throws Exception {
|
||||
Duration duration = Duration.ofSeconds(1234);
|
||||
long seconds = duration.getSeconds();
|
||||
|
||||
@@ -67,37 +63,34 @@ public class ScalarTypeDurationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatValue() throws Exception {
|
||||
|
||||
void testFormatValue() {
|
||||
Duration duration = Duration.ofSeconds(1234);
|
||||
String formatValue = type.formatValue(duration);
|
||||
assertEquals("PT20M34S", formatValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() {
|
||||
void testParse() {
|
||||
Duration duration = type.parse("PT20M34S");
|
||||
assertEquals(Duration.ofSeconds(1234), duration);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDateTimeCapable() {
|
||||
void testIsDateTimeCapable() {
|
||||
assertFalse(type.isDateTimeCapable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromMillis() {
|
||||
assertThrows(TextException.class, () -> type.convertFromMillis(1000));
|
||||
void testConvertFromMillis() {
|
||||
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonRead() throws Exception {
|
||||
|
||||
void testJsonRead() throws Exception {
|
||||
Duration duration = Duration.ofSeconds(1234);
|
||||
|
||||
JsonTester<Duration> jsonTester = new JsonTester<>(type);
|
||||
jsonTester.test(duration);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+10
-15
@@ -1,6 +1,5 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import io.ebean.text.TextException;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@@ -12,13 +11,12 @@ import java.time.Duration;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ScalarTypeDurationWithNanosTest {
|
||||
class ScalarTypeDurationWithNanosTest {
|
||||
|
||||
ScalarTypeDurationWithNanos type = new ScalarTypeDurationWithNanos();
|
||||
|
||||
@Test
|
||||
public void testReadData() throws Exception {
|
||||
|
||||
void testReadData() throws Exception {
|
||||
Duration duration = Duration.ofSeconds(323, 1500000);
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
@@ -40,8 +38,7 @@ public class ScalarTypeDurationWithNanosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToJdbcType() throws Exception {
|
||||
|
||||
void testToJdbcType() throws Exception {
|
||||
Duration duration = Duration.ofSeconds(323, 1500000);
|
||||
BigDecimal bigDecimal = DecimalUtils.toDecimal(duration);
|
||||
|
||||
@@ -53,8 +50,7 @@ public class ScalarTypeDurationWithNanosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToBeanType() throws Exception {
|
||||
|
||||
void testToBeanType() throws Exception {
|
||||
Duration duration = Duration.ofSeconds(323, 1500000);
|
||||
BigDecimal bigDecimal = DecimalUtils.toDecimal(duration);
|
||||
|
||||
@@ -66,32 +62,31 @@ public class ScalarTypeDurationWithNanosTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatValue() throws Exception {
|
||||
|
||||
void testFormatValue() {
|
||||
Duration duration = Duration.ofSeconds(323, 1500000);
|
||||
String formatValue = type.formatValue(duration);
|
||||
assertEquals("PT5M23.0015S", formatValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() {
|
||||
void testParse() {
|
||||
Duration duration = Duration.ofSeconds(323, 1500000);
|
||||
Duration val1 = type.parse("PT5M23.0015S");
|
||||
assertEquals(duration, val1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDateTimeCapable() {
|
||||
void testIsDateTimeCapable() {
|
||||
assertFalse(type.isDateTimeCapable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromMillis() {
|
||||
assertThrows(TextException.class, () -> type.convertFromMillis(1000));
|
||||
void testConvertFromMillis() {
|
||||
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJsonRead() throws Exception {
|
||||
void testJsonRead() throws Exception {
|
||||
Duration duration = Duration.ofSeconds(323, 1500000);
|
||||
|
||||
JsonTester<Duration> jsonTester = new JsonTester<>(type);
|
||||
|
||||
@@ -11,13 +11,12 @@ import java.time.Year;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class ScalarTypeYearTest {
|
||||
class ScalarTypeYearTest {
|
||||
|
||||
ScalarTypeYear type = new ScalarTypeYear();
|
||||
|
||||
@Test
|
||||
public void testReadData() throws Exception {
|
||||
|
||||
void testReadData() throws Exception {
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
ObjectOutputStream out = new ObjectOutputStream(os);
|
||||
|
||||
@@ -37,8 +36,7 @@ public class ScalarTypeYearTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToJdbcType() throws Exception {
|
||||
|
||||
void testToJdbcType() throws Exception {
|
||||
Integer year = 2013;
|
||||
Object val1 = type.toJdbcType(Year.of(2013));
|
||||
Object val2 = type.toJdbcType(2013);
|
||||
@@ -50,8 +48,7 @@ public class ScalarTypeYearTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToBeanType() throws Exception {
|
||||
|
||||
void testToBeanType() throws Exception {
|
||||
Year year = Year.of(2013);
|
||||
Year val1 = type.toBeanType(year);
|
||||
Year val2 = type.toBeanType(2013);
|
||||
@@ -63,29 +60,29 @@ public class ScalarTypeYearTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatValue() throws Exception {
|
||||
void testFormatValue() {
|
||||
String formatted = type.formatValue(Year.of(2013));
|
||||
assertEquals("2013", formatted);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParse() {
|
||||
void testParse() {
|
||||
Year year = type.parse("2013");
|
||||
assertEquals(Year.of(2013), year);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsDateTimeCapable() {
|
||||
void testIsDateTimeCapable() {
|
||||
assertFalse(type.isDateTimeCapable());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConvertFromMillis() {
|
||||
assertThrows(TextException.class, () -> type.convertFromMillis(1000));
|
||||
void testConvertFromMillis() {
|
||||
assertThrows(UnsupportedOperationException.class, () -> type.convertFromMillis(1000));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJson() throws Exception {
|
||||
void testJson() throws Exception {
|
||||
JsonTester<Year> jsonTester = new JsonTester<>(type);
|
||||
jsonTester.test(Year.of(2013));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user