1717package io .r2dbc .postgresql ;
1818
1919import io .netty .buffer .ByteBuf ;
20+ import io .r2dbc .postgresql .codec .Codecs ;
2021import io .r2dbc .postgresql .codec .MockCodecs ;
2122import io .r2dbc .postgresql .message .backend .DataRow ;
2223import io .r2dbc .postgresql .message .backend .RowDescription ;
2829import java .util .Collections ;
2930import java .util .List ;
3031import java .util .NoSuchElementException ;
32+ import java .util .stream .Collectors ;
3133
3234import static io .r2dbc .postgresql .message .Format .FORMAT_BINARY ;
3335import static io .r2dbc .postgresql .message .Format .FORMAT_TEXT ;
@@ -51,6 +53,11 @@ final class PostgresqlRowUnitTests {
5153 new RowDescription .Field ((short ) 400 , 400 , 300 , (short ) 400 , FORMAT_TEXT , "test-name-3" , 500 )
5254 );
5355
56+ private final PostgresqlRowMetadata metadata = new PostgresqlRowMetadata (columns
57+ .stream ()
58+ .map (field -> PostgresqlColumnMetadata .toColumnMetadata (mock (Codecs .class ), field ))
59+ .collect (Collectors .toList ()));
60+
5461 private final ByteBuf [] data = new ByteBuf []{TEST .buffer (4 ).writeInt (100 ), TEST .buffer (4 ).writeInt (300 ), null };
5562
5663 @ AfterEach
@@ -78,7 +85,7 @@ void getAfterRelease() {
7885 .decoding (TEST .buffer (4 ).writeInt (300 ), 400 , FORMAT_TEXT , Object .class , value )
7986 .build ();
8087
81- PostgresqlRow row = new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , new ByteBuf [0 ]);
88+ PostgresqlRow row = new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , new ByteBuf [0 ]);
8289 row .release ();
8390
8491 assertThatIllegalStateException ().isThrownBy (() -> row .get ("test-name-2" , Object .class ))
@@ -93,7 +100,7 @@ void getDefaultType() {
93100 .decoding (TEST .buffer (4 ).writeInt (300 ), 400 , FORMAT_TEXT , Object .class , value )
94101 .build ();
95102
96- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get ("test-name-2" )).isSameAs (value );
103+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get ("test-name-2" )).isSameAs (value );
97104 }
98105
99106 @ Test
@@ -104,20 +111,20 @@ void getIndex() {
104111 .decoding (TEST .buffer (4 ).writeInt (300 ), 400 , FORMAT_TEXT , Object .class , value )
105112 .build ();
106113
107- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get (1 , Object .class )).isSameAs (value );
114+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get (1 , Object .class )).isSameAs (value );
108115 }
109116
110117 @ Test
111118 void getInvalidIndex () {
112- assertThatExceptionOfType (IndexOutOfBoundsException .class ).isThrownBy (() -> new PostgresqlRow (MockContext .empty (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns ,
119+ assertThatExceptionOfType (IndexOutOfBoundsException .class ).isThrownBy (() -> new PostgresqlRow (MockContext .empty (), this . metadata , this .columns ,
113120 new ByteBuf [0 ]).get (3 ,
114121 Object .class ))
115122 .withMessage ("Column index 3 is larger than the number of columns 3" );
116123 }
117124
118125 @ Test
119126 void getInvalidName () {
120- assertThatExceptionOfType (NoSuchElementException .class ).isThrownBy (() -> new PostgresqlRow (MockContext .empty (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns ,
127+ assertThatExceptionOfType (NoSuchElementException .class ).isThrownBy (() -> new PostgresqlRow (MockContext .empty (), this . metadata , this .columns ,
121128 new ByteBuf [0 ]).get ("test-name" +
122129 "-4" , Object .class ))
123130 .withMessageMatching ("Column name 'test-name-4' does not exist in column names \\ [test-name-[\\ d], test-name-[\\ d], test-name-[\\ d]\\ ]" );
@@ -131,20 +138,20 @@ void getName() {
131138 .decoding (TEST .buffer (4 ).writeInt (300 ), 400 , FORMAT_TEXT , Object .class , value )
132139 .build ();
133140
134- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get ("test-name-2" , Object .class )).isSameAs (value );
135- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get ("tEsT-nAme-2" , Object .class )).isSameAs (value );
141+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get ("test-name-2" , Object .class )).isSameAs (value );
142+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get ("tEsT-nAme-2" , Object .class )).isSameAs (value );
136143 }
137144
138145 @ Test
139146 void getNoIdentifier () {
140- assertThatIllegalArgumentException ().isThrownBy (() -> new PostgresqlRow (MockContext .empty (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , new ByteBuf [0 ]).get (null ,
147+ assertThatIllegalArgumentException ().isThrownBy (() -> new PostgresqlRow (MockContext .empty (), this . metadata , this .columns , new ByteBuf [0 ]).get (null ,
141148 Object .class ))
142149 .withMessage ("name must not be null" );
143150 }
144151
145152 @ Test
146153 void getNoType () {
147- assertThatIllegalArgumentException ().isThrownBy (() -> new PostgresqlRow (MockContext .empty (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , new ByteBuf [0 ]).get ("" , null ))
154+ assertThatIllegalArgumentException ().isThrownBy (() -> new PostgresqlRow (MockContext .empty (), this . metadata , this .columns , new ByteBuf [0 ]).get ("" , null ))
148155 .withMessage ("type must not be null" );
149156 }
150157
@@ -154,7 +161,7 @@ void getNull() {
154161 .decoding (null , 400 , FORMAT_TEXT , Object .class , null )
155162 .build ();
156163
157- assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), new PostgresqlRowMetadata ( Collections . emptyList ()) , this .columns , this .data ).get ("test-name-3" , Object .class )).isNull ();
164+ assertThat (new PostgresqlRow (MockContext .builder ().codecs (codecs ).build (), this . metadata , this .columns , this .data ).get ("test-name-3" , Object .class )).isNull ();
158165 }
159166
160167 @ Test
0 commit comments