@@ -55,7 +55,9 @@ final class PostgisGeometryCodecUnitTests {
5555
5656 private static final int dataType = 23456 ;
5757
58- private final PostgisGeometryCodec codec = new PostgisGeometryCodec (dataType );
58+ private final PostgisGeometryCodec geometryCodec = new PostgisGeometryCodec (dataType );
59+
60+ private final PostgisGeographyCodec geographyCodec = new PostgisGeographyCodec (dataType );
5961
6062 private final WKBWriter wkbWriter = new WKBWriter ();
6163
@@ -65,91 +67,167 @@ final class PostgisGeometryCodecUnitTests {
6567
6668 @ Test
6769 void canDecodeNoFormat () {
68- assertThatIllegalArgumentException ().isThrownBy (() -> this .codec .canDecode (dataType , null , Geometry .class ))
70+ assertThatIllegalArgumentException ().isThrownBy (() -> this .geometryCodec .canDecode (dataType , null , Geometry .class ))
6971 .withMessage ("format must not be null" );
7072 }
7173
7274 @ Test
7375 void canDecodeNoClass () {
74- assertThatIllegalArgumentException ().isThrownBy (() -> this .codec .canDecode (dataType , FORMAT_TEXT , null ))
76+ assertThatIllegalArgumentException ().isThrownBy (() -> this .geometryCodec .canDecode (dataType , FORMAT_TEXT , null ))
7577 .withMessage ("type must not be null" );
7678 }
7779
7880 @ Test
79- void canDecode () {
80- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , Geometry .class )).isTrue ();
81- assertThat (this .codec .canDecode (dataType , FORMAT_BINARY , Geometry .class )).isTrue ();
82-
83- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , Point .class )).isTrue ();
84- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , MultiPoint .class )).isTrue ();
85- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , LineString .class )).isTrue ();
86- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , LinearRing .class )).isTrue ();
87- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , MultiLineString .class )).isTrue ();
88- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , Polygon .class )).isTrue ();
89- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , MultiPolygon .class )).isTrue ();
90- assertThat (this .codec .canDecode (dataType , FORMAT_TEXT , GeometryCollection .class )).isTrue ();
81+ void canDecodeGeometry () {
82+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , Geometry .class )).isTrue ();
83+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_BINARY , Geometry .class )).isTrue ();
84+
85+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , Point .class )).isTrue ();
86+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , MultiPoint .class )).isTrue ();
87+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , LineString .class )).isTrue ();
88+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , LinearRing .class )).isTrue ();
89+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , MultiLineString .class )).isTrue ();
90+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , Polygon .class )).isTrue ();
91+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , MultiPolygon .class )).isTrue ();
92+ assertThat (this .geometryCodec .canDecode (dataType , FORMAT_TEXT , GeometryCollection .class )).isTrue ();
93+
94+ assertThat (this .geometryCodec .canDecode (VARCHAR .getObjectId (), FORMAT_BINARY , Geometry .class )).isFalse ();
95+ assertThat (this .geometryCodec .canDecode (JSON .getObjectId (), FORMAT_TEXT , Geometry .class )).isFalse ();
96+ assertThat (this .geometryCodec .canDecode (JSONB .getObjectId (), FORMAT_BINARY , Geometry .class )).isFalse ();
97+ }
9198
92- assertThat (this .codec .canDecode (VARCHAR .getObjectId (), FORMAT_BINARY , Geometry .class )).isFalse ();
93- assertThat (this .codec .canDecode (JSON .getObjectId (), FORMAT_TEXT , Geometry .class )).isFalse ();
94- assertThat (this .codec .canDecode (JSONB .getObjectId (), FORMAT_BINARY , Geometry .class )).isFalse ();
99+ @ Test
100+ void canDecodeGeography () {
101+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , Geometry .class )).isTrue ();
102+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_BINARY , Geometry .class )).isTrue ();
103+
104+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , Point .class )).isTrue ();
105+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , MultiPoint .class )).isTrue ();
106+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , LineString .class )).isTrue ();
107+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , LinearRing .class )).isTrue ();
108+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , MultiLineString .class )).isTrue ();
109+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , Polygon .class )).isTrue ();
110+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , MultiPolygon .class )).isTrue ();
111+ assertThat (this .geographyCodec .canDecode (dataType , FORMAT_TEXT , GeometryCollection .class )).isTrue ();
112+
113+ assertThat (this .geographyCodec .canDecode (VARCHAR .getObjectId (), FORMAT_BINARY , Geometry .class )).isFalse ();
114+ assertThat (this .geographyCodec .canDecode (JSON .getObjectId (), FORMAT_TEXT , Geometry .class )).isFalse ();
115+ assertThat (this .geographyCodec .canDecode (JSONB .getObjectId (), FORMAT_BINARY , Geometry .class )).isFalse ();
95116 }
96117
97118 @ Test
98- void canEncodeNoValue () {
99- assertThatIllegalArgumentException ().isThrownBy (() -> this .codec .canEncode (null ))
119+ void canEncodeNoValueGeometry () {
120+ assertThatIllegalArgumentException ().isThrownBy (() -> this .geometryCodec .canEncode (null ))
100121 .withMessage ("value must not be null" );
101122 }
102123
124+ void canEncodeNoValueGeography () {
125+ assertThatIllegalArgumentException ().isThrownBy (() -> this .geographyCodec .canEncode (null ))
126+ .withMessage ("value must not be null" );
127+ }
128+
129+ @ Test
130+ void canEncodeGeometry () {
131+ assertThat (this .geometryCodec .canEncode (this .geometryFactory .createPoint ())).isTrue ();
132+ assertThat (this .geometryCodec .canEncode (this .geometryFactory .createMultiPoint ())).isTrue ();
133+ assertThat (this .geometryCodec .canEncode (this .geometryFactory .createLineString ())).isTrue ();
134+ assertThat (this .geometryCodec .canEncode (this .geometryFactory .createLinearRing ())).isTrue ();
135+ assertThat (this .geometryCodec .canEncode (this .geometryFactory .createMultiLineString ())).isTrue ();
136+ assertThat (this .geometryCodec .canEncode (this .geometryFactory .createPolygon ())).isTrue ();
137+ assertThat (this .geometryCodec .canEncode (this .geometryFactory .createMultiPolygon ())).isTrue ();
138+ assertThat (this .geometryCodec .canEncode (this .geometryFactory .createGeometryCollection ())).isTrue ();
139+
140+ assertThat (this .geometryCodec .canEncode ("Geometry" )).isFalse ();
141+ assertThat (this .geometryCodec .canEncode (1 )).isFalse ();
142+ }
143+
103144 @ Test
104- void canEncode () {
105- assertThat (this .codec .canEncode (this .geometryFactory .createPoint ())).isTrue ();
106- assertThat (this .codec .canEncode (this .geometryFactory .createMultiPoint ())).isTrue ();
107- assertThat (this .codec .canEncode (this .geometryFactory .createLineString ())).isTrue ();
108- assertThat (this .codec .canEncode (this .geometryFactory .createLinearRing ())).isTrue ();
109- assertThat (this .codec .canEncode (this .geometryFactory .createMultiLineString ())).isTrue ();
110- assertThat (this .codec .canEncode (this .geometryFactory .createPolygon ())).isTrue ();
111- assertThat (this .codec .canEncode (this .geometryFactory .createMultiPolygon ())).isTrue ();
112- assertThat (this .codec .canEncode (this .geometryFactory .createGeometryCollection ())).isTrue ();
145+ void canEncodeGeography () {
146+ assertThat (this .geographyCodec .canEncode (this .geometryFactory .createPoint ())).isTrue ();
147+ assertThat (this .geographyCodec .canEncode (this .geometryFactory .createMultiPoint ())).isTrue ();
148+ assertThat (this .geographyCodec .canEncode (this .geometryFactory .createLineString ())).isTrue ();
149+ assertThat (this .geographyCodec .canEncode (this .geometryFactory .createLinearRing ())).isTrue ();
150+ assertThat (this .geographyCodec .canEncode (this .geometryFactory .createMultiLineString ())).isTrue ();
151+ assertThat (this .geographyCodec .canEncode (this .geometryFactory .createPolygon ())).isTrue ();
152+ assertThat (this .geographyCodec .canEncode (this .geometryFactory .createMultiPolygon ())).isTrue ();
153+ assertThat (this .geographyCodec .canEncode (this .geometryFactory .createGeometryCollection ())).isTrue ();
154+
155+ assertThat (this .geographyCodec .canEncode ("Geography" )).isFalse ();
156+ assertThat (this .geographyCodec .canEncode (1 )).isFalse ();
157+ }
113158
114- assertThat (this .codec .canEncode ("Geometry" )).isFalse ();
115- assertThat (this .codec .canEncode (1 )).isFalse ();
159+ @ Test
160+ @ SuppressWarnings ("unchecked" )
161+ void decodeGeometry () {
162+ byte [] pointBytes = this .wkbWriter .write (this .point );
163+ ByteBuf pointByteBuf = ByteBufUtils .encode (TEST , WKBWriter .toHex (pointBytes ));
164+
165+ assertThat (this .geometryCodec .decode (pointByteBuf , dataType , FORMAT_TEXT , Geometry .class )).isEqualTo (this .point );
116166 }
117167
118168 @ Test
119169 @ SuppressWarnings ("unchecked" )
120- void decode () {
170+ void decodeGeography () {
121171 byte [] pointBytes = this .wkbWriter .write (this .point );
122172 ByteBuf pointByteBuf = ByteBufUtils .encode (TEST , WKBWriter .toHex (pointBytes ));
123173
124- assertThat (this .codec .decode (pointByteBuf , dataType , FORMAT_TEXT , Geometry .class )).isEqualTo (this .point );
174+ assertThat (this .geographyCodec .decode (pointByteBuf , dataType , FORMAT_TEXT , Geometry .class )).isEqualTo (this .point );
175+ }
176+
177+ @ Test
178+ @ SuppressWarnings ("unchecked" )
179+ void decodeNoByteBufGeometry () {
180+ assertThat (this .geometryCodec .decode (null , dataType , FORMAT_TEXT , Geometry .class )).isNull ();
125181 }
126182
127183 @ Test
128184 @ SuppressWarnings ("unchecked" )
129- void decodeNoByteBuf () {
130- assertThat (this .codec .decode (null , dataType , FORMAT_TEXT , Geometry .class )).isNull ();
185+ void decodeNoByteBufGeography () {
186+ assertThat (this .geographyCodec .decode (null , dataType , FORMAT_TEXT , Geometry .class )).isNull ();
187+ }
188+
189+ @ Test
190+ void encodeGeometry () {
191+ ByteBuf encoded = Unpooled .wrappedBuffer (new WKBWriter (2 , true ).write (this .point ));
192+
193+ ParameterAssert .assertThat (this .geometryCodec .encode (this .point ))
194+ .hasFormat (FORMAT_BINARY )
195+ .hasType (dataType )
196+ .hasValue (encoded );
131197 }
132198
133199 @ Test
134- void encode () {
200+ void encodeGeography () {
135201 ByteBuf encoded = Unpooled .wrappedBuffer (new WKBWriter (2 , true ).write (this .point ));
136202
137- ParameterAssert .assertThat (this .codec .encode (this .point ))
203+ ParameterAssert .assertThat (this .geographyCodec .encode (this .point ))
138204 .hasFormat (FORMAT_BINARY )
139205 .hasType (dataType )
140206 .hasValue (encoded );
141207 }
142208
143209 @ Test
144- void encodeNoValue () {
145- assertThatIllegalArgumentException ().isThrownBy (() -> this .codec .encode (null ))
210+ void encodeNoValueGeometry () {
211+ assertThatIllegalArgumentException ().isThrownBy (() -> this .geometryCodec .encode (null ))
212+ .withMessage ("value must not be null" );
213+ }
214+
215+ @ Test
216+ void encodeNoValueGeography () {
217+ assertThatIllegalArgumentException ().isThrownBy (() -> this .geometryCodec .encode (null ))
146218 .withMessage ("value must not be null" );
147219 }
148220
149221 @ Test
150- void encodeNull () {
222+ void encodeNullGeometry () {
151223 assertThat (new PostgisGeometryCodec (dataType ).encodeNull ())
152224 .isEqualTo (new EncodedParameter (FORMAT_BINARY , dataType , NULL_VALUE ));
153225 }
154226
227+ @ Test
228+ void encodeNullGeography () {
229+ assertThat (new PostgisGeographyCodec (dataType ).encodeNull ())
230+ .isEqualTo (new EncodedParameter (FORMAT_BINARY , dataType , NULL_VALUE ));
231+ }
232+
155233}
0 commit comments