Skip to content

Commit 700196f

Browse files
committed
Polishing.
Add since tags and license headers. Use parametrized tests. [#591][resolves #608]
1 parent e884a5d commit 700196f

File tree

14 files changed

+280
-171
lines changed

14 files changed

+280
-171
lines changed

README.md

Lines changed: 50 additions & 50 deletions
Large diffs are not rendered by default.

src/main/java/io/r2dbc/postgresql/codec/DayOfWeekCodec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
import java.time.DayOfWeek;
2222

23+
/**
24+
* @since 1.0.8
25+
*/
2326
final class DayOfWeekCodec extends IntegerCodecDelegate<DayOfWeek> {
2427

2528
DayOfWeekCodec(ByteBufAllocator byteBufAllocator) {
2629
super(DayOfWeek.class, byteBufAllocator, DayOfWeek::getValue, DayOfWeek::of);
2730
}
31+
2832
}

src/main/java/io/r2dbc/postgresql/codec/IntegerCodecDelegate.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
import java.util.function.Function;
2626

27+
/**
28+
* @since 1.0.8
29+
*/
2730
class IntegerCodecDelegate<T> extends AbstractCodec<T> {
2831

2932
private final IntegerCodec delegate;
@@ -39,35 +42,36 @@ class IntegerCodecDelegate<T> extends AbstractCodec<T> {
3942

4043
@Override
4144
boolean doCanDecode(PostgresqlObjectId type, Format format) {
42-
return delegate.doCanDecode(type, format);
45+
return this.delegate.doCanDecode(type, format);
4346
}
4447

4548
@Override
4649
T doDecode(ByteBuf buffer, PostgresTypeIdentifier dataType, Format format, Class<? extends T> type) {
47-
final Integer number = delegate.doDecode(buffer, dataType, format, Integer.TYPE);
48-
return fromIntegerConverter.apply(number);
50+
final Integer number = this.delegate.doDecode(buffer, dataType, format, Integer.TYPE);
51+
return this.fromIntegerConverter.apply(number);
4952
}
5053

5154
@Override
5255
EncodedParameter doEncode(T value) {
5356
Assert.requireNonNull(value, "value must not be null");
54-
return delegate.doEncode(toIntegerConverter.apply(value));
57+
return this.delegate.doEncode(this.toIntegerConverter.apply(value));
5558
}
5659

5760
@Override
5861
EncodedParameter doEncode(T value, PostgresTypeIdentifier dataType) {
5962
Assert.requireNonNull(value, "value must not be null");
6063
Assert.requireNonNull(dataType, "dataType must not be null");
61-
return delegate.doEncode(toIntegerConverter.apply(value), dataType);
64+
return this.delegate.doEncode(this.toIntegerConverter.apply(value), dataType);
6265
}
6366

6467
@Override
65-
public Iterable<? extends PostgresTypeIdentifier> getDataTypes() {
66-
return delegate.getDataTypes();
68+
public Iterable<PostgresTypeIdentifier> getDataTypes() {
69+
return this.delegate.getDataTypes();
6770
}
6871

6972
@Override
7073
public EncodedParameter encodeNull() {
71-
return delegate.encodeNull();
74+
return this.delegate.encodeNull();
7275
}
76+
7377
}

src/main/java/io/r2dbc/postgresql/codec/MonthCodec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
import java.time.Month;
2222

23+
/**
24+
* @since 1.0.8
25+
*/
2326
final class MonthCodec extends IntegerCodecDelegate<Month> {
2427

2528
MonthCodec(ByteBufAllocator byteBufAllocator) {
2629
super(Month.class, byteBufAllocator, Month::getValue, Month::of);
2730
}
31+
2832
}

src/main/java/io/r2dbc/postgresql/codec/MonthDayCodec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
import java.time.MonthDay;
2222

23+
/**
24+
* @since 1.0.8
25+
*/
2326
final class MonthDayCodec extends StringCodecDelegate<MonthDay> {
2427

2528
MonthDayCodec(ByteBufAllocator byteBufAllocator) {
2629
super(MonthDay.class, byteBufAllocator, MonthDay::toString, MonthDay::parse);
2730
}
31+
2832
}

src/main/java/io/r2dbc/postgresql/codec/PeriodCodec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
import java.time.Period;
2222

23+
/**
24+
* @since 1.0.8
25+
*/
2326
final class PeriodCodec extends StringCodecDelegate<Period> {
2427

2528
PeriodCodec(ByteBufAllocator byteBufAllocator) {
2629
super(Period.class, byteBufAllocator, Period::toString, Period::parse);
2730
}
31+
2832
}

src/main/java/io/r2dbc/postgresql/codec/YearCodec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
import java.time.Year;
2222

23+
/**
24+
* @since 1.0.8
25+
*/
2326
final class YearCodec extends IntegerCodecDelegate<Year> {
2427

2528
YearCodec(ByteBufAllocator byteBufAllocator) {
2629
super(Year.class, byteBufAllocator, Year::getValue, Year::of);
2730
}
31+
2832
}

src/main/java/io/r2dbc/postgresql/codec/YearMonthCodec.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020

2121
import java.time.YearMonth;
2222

23+
/**
24+
* @since 1.0.8
25+
*/
2326
final class YearMonthCodec extends StringCodecDelegate<YearMonth> {
2427

2528
YearMonthCodec(ByteBufAllocator byteBufAllocator) {
2629
super(YearMonth.class, byteBufAllocator, YearMonth::toString, YearMonth::parse);
2730
}
31+
2832
}
Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1+
/*
2+
* Copyright 2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package io.r2dbc.postgresql.codec;
218

319
import io.r2dbc.postgresql.client.EncodedParameter;
420
import io.r2dbc.postgresql.client.ParameterAssert;
521
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.EnumSource;
624

725
import java.time.DayOfWeek;
8-
import java.util.Arrays;
9-
import java.util.function.Consumer;
1026

1127
import static io.r2dbc.postgresql.client.EncodedParameter.NULL_VALUE;
12-
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.*;
28+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.INT2;
29+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.INT4;
30+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.INT8;
31+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.NUMERIC;
32+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.VARCHAR;
1333
import static io.r2dbc.postgresql.message.Format.FORMAT_BINARY;
1434
import static io.r2dbc.postgresql.message.Format.FORMAT_TEXT;
1535
import static io.r2dbc.postgresql.util.TestByteBufAllocator.TEST;
@@ -24,10 +44,10 @@ void constructorNoByteBufAllocator() {
2444
.withMessage("byteBufAllocator must not be null");
2545
}
2646

27-
@Test
28-
void decode() {
29-
forEveryDayOfWeek(d ->
30-
assertThat(new DayOfWeekCodec(TEST).decode(TEST.buffer().writeInt(d.getValue()), INT4, FORMAT_BINARY, DayOfWeek.class)).isEqualTo(d));
47+
@ParameterizedTest
48+
@EnumSource(DayOfWeek.class)
49+
void decode(DayOfWeek d) {
50+
assertThat(new DayOfWeekCodec(TEST).decode(TEST.buffer().writeInt(d.getValue()), INT4, FORMAT_BINARY, DayOfWeek.class)).isEqualTo(d);
3151
}
3252

3353
@Test
@@ -52,36 +72,31 @@ void doCanDecodeNoType() {
5272
.withMessage("type must not be null");
5373
}
5474

55-
@Test
56-
void doEncodeInt() {
57-
58-
forEveryDayOfWeek(d -> {
59-
ParameterAssert.assertThat(new DayOfWeekCodec(TEST).doEncode(d))
60-
.hasFormat(FORMAT_BINARY)
61-
.hasType(INT4.getObjectId())
62-
.hasValue(TEST.buffer().writeInt(d.getValue()));
63-
});
75+
@ParameterizedTest
76+
@EnumSource(DayOfWeek.class)
77+
void doEncodeInt(DayOfWeek d) {
78+
ParameterAssert.assertThat(new DayOfWeekCodec(TEST).doEncode(d))
79+
.hasFormat(FORMAT_BINARY)
80+
.hasType(INT4.getObjectId())
81+
.hasValue(TEST.buffer().writeInt(d.getValue()));
6482
}
6583

66-
@Test
67-
void doEncodeShort() {
68-
forEveryDayOfWeek(d -> {
69-
ParameterAssert.assertThat(new DayOfWeekCodec(TEST).doEncode(d, INT2))
70-
.hasFormat(FORMAT_BINARY)
71-
.hasType(INT2.getObjectId())
72-
.hasValue(TEST.buffer().writeShort(d.getValue()));
73-
});
84+
@ParameterizedTest
85+
@EnumSource(DayOfWeek.class)
86+
void doEncodeShort(DayOfWeek d) {
87+
ParameterAssert.assertThat(new DayOfWeekCodec(TEST).doEncode(d, INT2))
88+
.hasFormat(FORMAT_BINARY)
89+
.hasType(INT2.getObjectId())
90+
.hasValue(TEST.buffer().writeShort(d.getValue()));
7491
}
7592

76-
@Test
77-
void doEncodeLong() {
78-
79-
forEveryDayOfWeek(d -> {
80-
ParameterAssert.assertThat(new DayOfWeekCodec(TEST).doEncode(d, INT8))
81-
.hasFormat(FORMAT_BINARY)
82-
.hasType(INT8.getObjectId())
83-
.hasValue(TEST.buffer().writeLong(d.getValue()));
84-
});
93+
@ParameterizedTest
94+
@EnumSource(DayOfWeek.class)
95+
void doEncodeLong(DayOfWeek d) {
96+
ParameterAssert.assertThat(new DayOfWeekCodec(TEST).doEncode(d, INT8))
97+
.hasFormat(FORMAT_BINARY)
98+
.hasType(INT8.getObjectId())
99+
.hasValue(TEST.buffer().writeLong(d.getValue()));
85100
}
86101

87102
@Test
@@ -102,7 +117,4 @@ void encodeNull() {
102117
.isEqualTo(new EncodedParameter(FORMAT_BINARY, INT4.getObjectId(), NULL_VALUE));
103118
}
104119

105-
private void forEveryDayOfWeek(Consumer<DayOfWeek> assertion) {
106-
Arrays.stream(DayOfWeek.values()).forEach(assertion);
107-
}
108-
}
120+
}

src/test/java/io/r2dbc/postgresql/codec/MonthCodecTest.java

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1+
/*
2+
* Copyright 2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
package io.r2dbc.postgresql.codec;
218

319
import io.r2dbc.postgresql.client.EncodedParameter;
420
import io.r2dbc.postgresql.client.ParameterAssert;
521
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.EnumSource;
624

725
import java.time.Month;
8-
import java.util.Arrays;
9-
import java.util.function.Consumer;
1026

1127
import static io.r2dbc.postgresql.client.EncodedParameter.NULL_VALUE;
12-
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.*;
28+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.INT2;
29+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.INT4;
30+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.INT8;
31+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.NUMERIC;
32+
import static io.r2dbc.postgresql.codec.PostgresqlObjectId.VARCHAR;
1333
import static io.r2dbc.postgresql.message.Format.FORMAT_BINARY;
1434
import static io.r2dbc.postgresql.message.Format.FORMAT_TEXT;
1535
import static io.r2dbc.postgresql.util.TestByteBufAllocator.TEST;
@@ -25,10 +45,10 @@ void constructorNoByteBufAllocator() {
2545
}
2646

2747

28-
@Test
29-
void decode() {
30-
forEveryMonth(m ->
31-
assertThat(new MonthCodec(TEST).decode(TEST.buffer().writeInt(m.getValue()), INT4, FORMAT_BINARY, Month.class)).isEqualTo(m));
48+
@ParameterizedTest
49+
@EnumSource(Month.class)
50+
void decode(Month m) {
51+
assertThat(new MonthCodec(TEST).decode(TEST.buffer().writeInt(m.getValue()), INT4, FORMAT_BINARY, Month.class)).isEqualTo(m);
3252
}
3353

3454
@Test
@@ -53,36 +73,31 @@ void doCanDecodeNoType() {
5373
.withMessage("type must not be null");
5474
}
5575

56-
@Test
57-
void doEncodeInt() {
58-
59-
forEveryMonth(m -> {
60-
ParameterAssert.assertThat(new MonthCodec(TEST).doEncode(m))
61-
.hasFormat(FORMAT_BINARY)
62-
.hasType(INT4.getObjectId())
63-
.hasValue(TEST.buffer().writeInt(m.getValue()));
64-
});
76+
@ParameterizedTest
77+
@EnumSource(Month.class)
78+
void doEncodeInt(Month m) {
79+
ParameterAssert.assertThat(new MonthCodec(TEST).doEncode(m))
80+
.hasFormat(FORMAT_BINARY)
81+
.hasType(INT4.getObjectId())
82+
.hasValue(TEST.buffer().writeInt(m.getValue()));
6583
}
6684

67-
@Test
68-
void doEncodeShort() {
69-
forEveryMonth(m -> {
70-
ParameterAssert.assertThat(new MonthCodec(TEST).doEncode(m, INT2))
71-
.hasFormat(FORMAT_BINARY)
72-
.hasType(INT2.getObjectId())
73-
.hasValue(TEST.buffer().writeShort(m.getValue()));
74-
});
85+
@ParameterizedTest
86+
@EnumSource(Month.class)
87+
void doEncodeShort(Month m) {
88+
ParameterAssert.assertThat(new MonthCodec(TEST).doEncode(m, INT2))
89+
.hasFormat(FORMAT_BINARY)
90+
.hasType(INT2.getObjectId())
91+
.hasValue(TEST.buffer().writeShort(m.getValue()));
7592
}
7693

77-
@Test
78-
void doEncodeLong() {
79-
80-
forEveryMonth(m -> {
81-
ParameterAssert.assertThat(new MonthCodec(TEST).doEncode(m, INT8))
82-
.hasFormat(FORMAT_BINARY)
83-
.hasType(INT8.getObjectId())
84-
.hasValue(TEST.buffer().writeLong(m.getValue()));
85-
});
94+
@ParameterizedTest
95+
@EnumSource(Month.class)
96+
void doEncodeLong(Month m) {
97+
ParameterAssert.assertThat(new MonthCodec(TEST).doEncode(m, INT8))
98+
.hasFormat(FORMAT_BINARY)
99+
.hasType(INT8.getObjectId())
100+
.hasValue(TEST.buffer().writeLong(m.getValue()));
86101
}
87102

88103
@Test
@@ -103,7 +118,4 @@ void encodeNull() {
103118
.isEqualTo(new EncodedParameter(FORMAT_BINARY, INT4.getObjectId(), NULL_VALUE));
104119
}
105120

106-
private void forEveryMonth(Consumer<Month> assertion) {
107-
Arrays.stream(Month.values()).forEach(assertion);
108-
}
109-
}
121+
}

0 commit comments

Comments
 (0)