1
1
package de .zalando .typemapper .postgres ;
2
2
3
3
import java .sql .SQLException ;
4
- import java .time .Instant ;
5
- import java .time .format . DateTimeFormatter ;
4
+ import java .time .LocalDateTime ;
5
+ import java .time .ZoneId ;
6
6
import java .util .Arrays ;
7
7
import java .util .Collection ;
8
8
import java .util .Date ;
@@ -43,9 +43,9 @@ public PgSerializerTest(final Object objectToSerialize, final Object expected) {
43
43
this .expectedString = null ;
44
44
this .expectedPattern = (Pattern ) expected ;
45
45
} else {
46
- throw new IllegalArgumentException (String .format (
47
- "Expected either a String or a Pattern, got: %s (%s)" ,
48
- expected , expected == null ? null : expected .getClass ()));
46
+ throw new IllegalArgumentException (String .format (
47
+ "Expected either a String or a Pattern, got: %s (%s)" ,
48
+ expected , expected == null ? null : expected .getClass ()));
49
49
}
50
50
}
51
51
@@ -58,33 +58,39 @@ public PgSerializerTest(final Object objectToSerialize, final Object expected) {
58
58
@ SuppressWarnings ("deprecation" )
59
59
@ Parameters
60
60
public static Collection <Object []> generateData () throws SQLException {
61
+
61
62
return Arrays .asList (
62
- new Object [][] {
63
- {new Date (112 , 11 , 1 , 6 , 6 , 6 ), Pattern .compile ("2012-12-01 06:06:06[+-]?\\ d{2}" )},
64
- {new Date (112 , 9 , 1 , 6 , 6 , 6 ), Pattern .compile ("2012-10-01 06:06:06[+-]?\\ d{2}" )},
65
- {Date .from (DateTimeFormatter .ISO_OFFSET_DATE_TIME .parse ("2017-05-14T12:34:56.123456789+02:00" , Instant ::from )), Pattern .compile ("2017-05-14 12:34:56.123000[+-]?\\ d{2}" )},
66
- {1 , "1" },
67
- {69 , "69" },
68
- {true , "t" },
69
- {new int [] {1 , 2 , 3 , 4 }, "{1,2,3,4}" },
70
- {new Integer [] {null , 2 , 3 , 4 }, "{NULL,2,3,4}" },
71
- {ARRAY ("a" , "b" ).asJdbcArray ("text" ), "{a,b}" },
72
- {ARRAY ("a" , "b(x)" ).asJdbcArray ("text" ), "{a,b(x)}" },
73
- {ARRAY ("a" , "b{x}" ).asJdbcArray ("text" ), "{a,\" b{x}\" }" },
74
- {
75
- ARRAY ("first element" , "second \" quoted\" element" ).asJdbcArray ("text" ),
76
- "{\" first element\" ,\" second \\ \" quoted\\ \" element\" }"
77
- },
78
- {ROW (1 , 2 ), "(1,2)" },
79
- {ROW ("a" , "b{x}" ), "(a,b{x})" },
80
- {ROW ("a" , "b(x)" ), "(a,\" b(x)\" )" },
81
- {ROW (1 , 2 , ARRAY ("a" , "b" )), "(1,2,\" {a,b}\" )" },
82
- {ROW ("a" , "b" , new int [] {1 , 2 , 3 , 4 }), "(a,b,\" {1,2,3,4}\" )" },
83
- {ROW ("a" , null , ARRAY (ROW (1 ), ROW (2 ), null )), "(a,,\" {(1),(2),NULL}\" )" },
84
- {
85
- ROW ("a" , null , ARRAY (ROW (1 , 11 ), ROW (2 , 22 ), null )),
86
- "(a,,\" {\" \" (1,11)\" \" ,\" \" (2,22)\" \" ,NULL}\" )"
87
- },
63
+ new Object [][]{
64
+ {new Date (112 , 11 , 1 , 6 , 6 , 6 ), Pattern .compile ("2012-12-01 06:06:06[+-]?\\ d{2}" )},
65
+ {new Date (112 , 9 , 1 , 6 , 6 , 6 ), Pattern .compile ("2012-10-01 06:06:06[+-]?\\ d{2}" )},
66
+ {Date .from (
67
+ LocalDateTime .of (2017 , 5 , 14 , 12 , 34 , 56 , 123456789 )
68
+ .atZone (ZoneId .systemDefault ())
69
+ .toInstant ()
70
+ ),
71
+ Pattern .compile ("2017-05-14 12:34:56.123000[+-]?\\ d{2}" )},
72
+ {1 , "1" },
73
+ {69 , "69" },
74
+ {true , "t" },
75
+ {new int []{1 , 2 , 3 , 4 }, "{1,2,3,4}" },
76
+ {new Integer []{null , 2 , 3 , 4 }, "{NULL,2,3,4}" },
77
+ {ARRAY ("a" , "b" ).asJdbcArray ("text" ), "{a,b}" },
78
+ {ARRAY ("a" , "b(x)" ).asJdbcArray ("text" ), "{a,b(x)}" },
79
+ {ARRAY ("a" , "b{x}" ).asJdbcArray ("text" ), "{a,\" b{x}\" }" },
80
+ {
81
+ ARRAY ("first element" , "second \" quoted\" element" ).asJdbcArray ("text" ),
82
+ "{\" first element\" ,\" second \\ \" quoted\\ \" element\" }"
83
+ },
84
+ {ROW (1 , 2 ), "(1,2)" },
85
+ {ROW ("a" , "b{x}" ), "(a,b{x})" },
86
+ {ROW ("a" , "b(x)" ), "(a,\" b(x)\" )" },
87
+ {ROW (1 , 2 , ARRAY ("a" , "b" )), "(1,2,\" {a,b}\" )" },
88
+ {ROW ("a" , "b" , new int []{1 , 2 , 3 , 4 }), "(a,b,\" {1,2,3,4}\" )" },
89
+ {ROW ("a" , null , ARRAY (ROW (1 ), ROW (2 ), null )), "(a,,\" {(1),(2),NULL}\" )" },
90
+ {
91
+ ROW ("a" , null , ARRAY (ROW (1 , 11 ), ROW (2 , 22 ), null )),
92
+ "(a,,\" {\" \" (1,11)\" \" ,\" \" (2,22)\" \" ,NULL}\" )"
93
+ },
88
94
});
89
95
}
90
96
0 commit comments