From 17f408681c1734d8bb111f0990f459fb63c626af Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Thu, 24 Mar 2022 12:01:22 +1300 Subject: [PATCH] No functional change - final methods on internal RsetDataReader --- .../server/type/RsetDataReader.java | 54 ++++++++-------- .../server/type/TestTypeManager.java | 61 ++++++++----------- 2 files changed, 54 insertions(+), 61 deletions(-) diff --git a/ebean-core/src/main/java/io/ebeaninternal/server/type/RsetDataReader.java b/ebean-core/src/main/java/io/ebeaninternal/server/type/RsetDataReader.java index 574f37615..6469f8346 100644 --- a/ebean-core/src/main/java/io/ebeaninternal/server/type/RsetDataReader.java +++ b/ebean-core/src/main/java/io/ebeaninternal/server/type/RsetDataReader.java @@ -34,28 +34,28 @@ public class RsetDataReader implements DataReader { } @Override - public void pushJson(String json) { + public final void pushJson(String json) { this.json = json; } @Override - public String popJson() { + public final String popJson() { return json; } @Override - public void close() throws SQLException { + public final void close() throws SQLException { rset.close(); } @Override - public boolean next() throws SQLException { + public final boolean next() throws SQLException { pos = 0; return rset.next(); } @Override - public void incrementPos(int increment) { + public final void incrementPos(int increment) { pos += increment; } @@ -64,49 +64,49 @@ public class RsetDataReader implements DataReader { } @Override - public Array getArray() throws SQLException { + public final Array getArray() throws SQLException { return rset.getArray(pos()); } @Override - public Object getObject() throws SQLException { + public final Object getObject() throws SQLException { return rset.getObject(pos()); } @Override - public T getObject(Class cls) throws SQLException { + public final T getObject(Class cls) throws SQLException { return rset.getObject(pos(), cls); } @Override - public BigDecimal getBigDecimal() throws SQLException { + public final BigDecimal getBigDecimal() throws SQLException { return rset.getBigDecimal(pos()); } @Override - public InputStream getBinaryStream() throws SQLException { + public final InputStream getBinaryStream() throws SQLException { return rset.getBinaryStream(pos()); } @Override - public Boolean getBoolean() throws SQLException { + public final Boolean getBoolean() throws SQLException { boolean v = rset.getBoolean(pos()); return rset.wasNull() ? null : v; } @Override - public Byte getByte() throws SQLException { + public final Byte getByte() throws SQLException { byte v = rset.getByte(pos()); return rset.wasNull() ? null : v; } @Override - public byte[] getBytes() throws SQLException { + public final byte[] getBytes() throws SQLException { return rset.getBytes(pos()); } @Override - public Date getDate() throws SQLException { + public final Date getDate() throws SQLException { Calendar cal = dataTimeZone.getDateTimeZone(); if (cal != null) { return rset.getDate(pos(), cal); @@ -116,46 +116,46 @@ public class RsetDataReader implements DataReader { } @Override - public Double getDouble() throws SQLException { + public final Double getDouble() throws SQLException { double v = rset.getDouble(pos()); return rset.wasNull() ? null : v; } @Override - public Float getFloat() throws SQLException { + public final Float getFloat() throws SQLException { float v = rset.getFloat(pos()); return rset.wasNull() ? null : v; } @Override - public Integer getInt() throws SQLException { + public final Integer getInt() throws SQLException { int v = rset.getInt(pos()); return rset.wasNull() ? null : v; } @Override - public Long getLong() throws SQLException { + public final Long getLong() throws SQLException { long v = rset.getLong(pos()); return rset.wasNull() ? null : v; } - public Ref getRef() throws SQLException { + public final Ref getRef() throws SQLException { return rset.getRef(pos()); } @Override - public Short getShort() throws SQLException { + public final Short getShort() throws SQLException { short s = rset.getShort(pos()); return rset.wasNull() ? null : s; } @Override - public String getString() throws SQLException { + public final String getString() throws SQLException { return rset.getString(pos()); } @Override - public Time getTime() throws SQLException { + public final Time getTime() throws SQLException { Calendar cal = dataTimeZone.getTimeZone(); if (cal != null) { return rset.getTime(pos(), cal); @@ -165,7 +165,7 @@ public class RsetDataReader implements DataReader { } @Override - public Timestamp getTimestamp() throws SQLException { + public final Timestamp getTimestamp() throws SQLException { Calendar cal = dataTimeZone.getTimeZone(); if (cal != null) { return rset.getTimestamp(pos(), cal); @@ -175,12 +175,12 @@ public class RsetDataReader implements DataReader { } @Override - public String getStringFromStream() throws SQLException { + public final String getStringFromStream() throws SQLException { Reader reader = rset.getCharacterStream(pos()); return reader == null ? null : readStringLob(reader); } - protected String readStringLob(Reader reader) throws SQLException { + private String readStringLob(Reader reader) throws SQLException { char[] buffer = new char[clobBufferSize]; int readLength; StringBuilder out = new StringBuilder(stringInitialSize); @@ -196,12 +196,12 @@ public class RsetDataReader implements DataReader { } @Override - public byte[] getBinaryBytes() throws SQLException { + public final byte[] getBinaryBytes() throws SQLException { InputStream in = rset.getBinaryStream(pos()); return getBinaryLob(in); } - protected byte[] getBinaryLob(InputStream in) throws SQLException { + private byte[] getBinaryLob(InputStream in) throws SQLException { if (in == null) { return null; } diff --git a/ebean-test/src/test/java/io/ebeaninternal/server/type/TestTypeManager.java b/ebean-test/src/test/java/io/ebeaninternal/server/type/TestTypeManager.java index 94aa02e3d..d46c0afef 100644 --- a/ebean-test/src/test/java/io/ebeaninternal/server/type/TestTypeManager.java +++ b/ebean-test/src/test/java/io/ebeaninternal/server/type/TestTypeManager.java @@ -3,6 +3,7 @@ package io.ebeaninternal.server.type; import io.ebean.BaseTestCase; import io.ebean.config.DatabaseConfig; import io.ebean.config.dbplatform.h2.H2Platform; +import io.ebean.core.type.DataReader; import io.ebean.core.type.ScalarType; import io.ebean.server.type.MyDayOfWeek; import io.ebean.server.type.MyEnum; @@ -21,21 +22,26 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; -public class TestTypeManager extends BaseTestCase { +class TestTypeManager extends BaseTestCase { @Test - public void testEnumWithSubclasses() throws SQLException { - + void testEnumWithSubclasses() throws SQLException { DefaultTypeManager typeManager = createTypeManager(); ScalarType type = typeManager.createEnumScalarType(MyEnum.class, null); - Object val = type.read(new DummyDataReader("A")); + DataReader reader = mock(DataReader.class); + when(reader.getString()).thenReturn("A"); + Object val = type.read(reader); assertThat(val).isEqualTo(MyEnum.Aval); - val = type.read(new DummyDataReader("B")); + when(reader.getString()).thenReturn("B"); + val = type.read(reader); assertThat(val).isEqualTo(MyEnum.Bval); - val = type.read(new DummyDataReader("C")); + when(reader.getString()).thenReturn("C"); + val = type.read(reader); assertThat(val).isEqualTo(MyEnum.Cval); ScalarType typeGeneral = typeManager.getScalarType(MyEnum.class); @@ -56,25 +62,29 @@ public class TestTypeManager extends BaseTestCase { } @Test - public void testEnumWithChar() throws SQLException { - + void testEnumWithChar() throws SQLException { DefaultTypeManager typeManager = createTypeManager(); ScalarType dayOfWeekType = typeManager.createEnumScalarType(MyDayOfWeek.class, null); - - Object val = dayOfWeekType.read(new DummyDataReader("MONDAY ")); + DataReader reader = mock(DataReader.class); + when(reader.getString()).thenReturn("MONDAY "); + Object val = dayOfWeekType.read(reader); assertThat(val).isEqualTo(MyDayOfWeek.MONDAY); - val = dayOfWeekType.read(new DummyDataReader("TUESDAY ")); + when(reader.getString()).thenReturn("TUESDAY "); + val = dayOfWeekType.read(reader); assertThat(val).isEqualTo(MyDayOfWeek.TUESDAY); - val = dayOfWeekType.read(new DummyDataReader("WEDNESDAY")); + when(reader.getString()).thenReturn("WEDNESDAY"); + val = dayOfWeekType.read(reader); assertThat(val).isEqualTo(MyDayOfWeek.WEDNESDAY); - val = dayOfWeekType.read(new DummyDataReader("THURSDAY ")); + when(reader.getString()).thenReturn("THURSDAY "); + val = dayOfWeekType.read(reader); assertThat(val).isEqualTo(MyDayOfWeek.THURSDAY); - val = dayOfWeekType.read(new DummyDataReader("FRIDAY ")); + when(reader.getString()).thenReturn("FRIDAY "); + val = dayOfWeekType.read(reader); assertThat(val).isEqualTo(MyDayOfWeek.FRIDAY); try { @@ -86,7 +96,7 @@ public class TestTypeManager extends BaseTestCase { } @Test - public void test() { + void test() { DefaultTypeManager typeManager = createTypeManager(); ScalarType scalarType = typeManager.getScalarType(Money.class); @@ -96,7 +106,7 @@ public class TestTypeManager extends BaseTestCase { } @Test - public void testWithConfig() { + void testWithConfig() { DefaultTypeManager typeManager1 = createTypeManager(); ScalarType type1 = typeManager1.createEnumScalarType(MySex.class, null); assertThat(type1).isInstanceOf(ScalarTypeEnumStandard.OrdinalEnum.class); @@ -132,27 +142,10 @@ public class TestTypeManager extends BaseTestCase { } @Test - public void testCalendar() throws SQLException { - + void testCalendar() { DefaultTypeManager typeManager = createTypeManager(); ScalarType typeB = typeManager.getScalarType(GregorianCalendar.class); assertThat(typeB).isInstanceOf(ScalarTypeCalendar.class); } - /** - * Test double DataReader implementation. - */ - private static class DummyDataReader extends RsetDataReader { - String val; - - DummyDataReader(String val) { - super(null, null); - this.val = val; - } - - @Override - public String getString() throws SQLException { - return val; - } - } }