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+
117package io .r2dbc .postgresql .codec ;
218
319import io .r2dbc .postgresql .client .EncodedParameter ;
420import io .r2dbc .postgresql .client .ParameterAssert ;
521import org .junit .jupiter .api .Test ;
22+ import org .junit .jupiter .params .ParameterizedTest ;
23+ import org .junit .jupiter .params .provider .EnumSource ;
624
725import java .time .DayOfWeek ;
8- import java .util .Arrays ;
9- import java .util .function .Consumer ;
1026
1127import 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 ;
1333import static io .r2dbc .postgresql .message .Format .FORMAT_BINARY ;
1434import static io .r2dbc .postgresql .message .Format .FORMAT_TEXT ;
1535import 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+ }
0 commit comments