119 {DAY_OF_MONTH, TextStyle.FULL, 30, "30"}, 120 {DAY_OF_MONTH, TextStyle.FULL, 31, "31"}, 121 122 {DAY_OF_MONTH, TextStyle.SHORT, 1, "1"}, 123 {DAY_OF_MONTH, TextStyle.SHORT, 2, "2"}, 124 {DAY_OF_MONTH, TextStyle.SHORT, 3, "3"}, 125 {DAY_OF_MONTH, TextStyle.SHORT, 28, "28"}, 126 {DAY_OF_MONTH, TextStyle.SHORT, 29, "29"}, 127 {DAY_OF_MONTH, TextStyle.SHORT, 30, "30"}, 128 {DAY_OF_MONTH, TextStyle.SHORT, 31, "31"}, 129 130 {MONTH_OF_YEAR, TextStyle.FULL, 1, "January"}, 131 {MONTH_OF_YEAR, TextStyle.FULL, 12, "December"}, 132 133 {MONTH_OF_YEAR, TextStyle.SHORT, 1, "Jan"}, 134 {MONTH_OF_YEAR, TextStyle.SHORT, 12, "Dec"}, 135 }; 136 } 137 138 @Test(dataProvider="printText", groups={"tck"}) 139 public void test_appendText2arg_print(TemporalField field, TextStyle style, int value, String expected) throws Exception { 140 DateTimeFormatter f = builder.appendText(field, style).toFormatter(Locale.ENGLISH); 141 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 142 dt = dt.with(field, value); 143 String text = f.print(dt); 144 assertEquals(text, expected); 145 } 146 147 @Test(dataProvider="printText", groups={"tck"}) 148 public void test_appendText1arg_print(TemporalField field, TextStyle style, int value, String expected) throws Exception { 149 if (style == TextStyle.FULL) { 150 DateTimeFormatter f = builder.appendText(field).toFormatter(Locale.ENGLISH); 151 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 152 dt = dt.with(field, value); 153 String text = f.print(dt); 154 assertEquals(text, expected); 155 } 156 } 157 158 //----------------------------------------------------------------------- 159 @Test(groups={"tck"}) 160 public void test_print_appendText2arg_french_long() throws Exception { 161 DateTimeFormatter f = builder.appendText(MONTH_OF_YEAR, TextStyle.FULL).toFormatter(Locale.FRENCH); 162 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 163 String text = f.print(dt); 164 assertEquals(text, "janvier"); 165 } 166 167 @Test(groups={"tck"}) 168 public void test_print_appendText2arg_french_short() throws Exception { 169 DateTimeFormatter f = builder.appendText(MONTH_OF_YEAR, TextStyle.SHORT).toFormatter(Locale.FRENCH); 170 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 171 String text = f.print(dt); 172 assertEquals(text, "janv."); 173 } 174 175 //----------------------------------------------------------------------- 176 @Test(groups={"tck"}) 177 public void test_appendTextMap() throws Exception { 178 Map<Long, String> map = new HashMap<Long, String>(); 179 map.put(1L, "JNY"); 180 map.put(2L, "FBY"); 181 map.put(3L, "MCH"); 182 map.put(4L, "APL"); 183 map.put(5L, "MAY"); 184 map.put(6L, "JUN"); 185 map.put(7L, "JLY"); 186 map.put(8L, "AGT"); 187 map.put(9L, "SPT"); 188 map.put(10L, "OBR"); 189 map.put(11L, "NVR"); 190 map.put(12L, "DBR"); 191 builder.appendText(MONTH_OF_YEAR, map); 192 DateTimeFormatter f = builder.toFormatter(); 193 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 194 for (Month month : Month.values()) { 195 assertEquals(f.print(dt.with(month)), map.get((long) month.getValue())); 196 } 197 } 198 199 @Test(groups={"tck"}) 200 public void test_appendTextMap_DOM() throws Exception { 201 Map<Long, String> map = new HashMap<Long, String>(); 202 map.put(1L, "1st"); 203 map.put(2L, "2nd"); 204 map.put(3L, "3rd"); 205 builder.appendText(DAY_OF_MONTH, map); 206 DateTimeFormatter f = builder.toFormatter(); 207 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 208 assertEquals(f.print(dt.withDayOfMonth(1)), "1st"); 209 assertEquals(f.print(dt.withDayOfMonth(2)), "2nd"); 210 assertEquals(f.print(dt.withDayOfMonth(3)), "3rd"); 211 } 212 213 @Test(groups={"tck"}) 214 public void test_appendTextMapIncomplete() throws Exception { 215 Map<Long, String> map = new HashMap<Long, String>(); 216 map.put(1L, "JNY"); 217 builder.appendText(MONTH_OF_YEAR, map); 218 DateTimeFormatter f = builder.toFormatter(); 219 LocalDateTime dt = LocalDateTime.of(2010, 2, 1, 0, 0); 220 assertEquals(f.print(dt), "2"); 221 } 222 223 } | 119 {DAY_OF_MONTH, TextStyle.FULL, 30, "30"}, 120 {DAY_OF_MONTH, TextStyle.FULL, 31, "31"}, 121 122 {DAY_OF_MONTH, TextStyle.SHORT, 1, "1"}, 123 {DAY_OF_MONTH, TextStyle.SHORT, 2, "2"}, 124 {DAY_OF_MONTH, TextStyle.SHORT, 3, "3"}, 125 {DAY_OF_MONTH, TextStyle.SHORT, 28, "28"}, 126 {DAY_OF_MONTH, TextStyle.SHORT, 29, "29"}, 127 {DAY_OF_MONTH, TextStyle.SHORT, 30, "30"}, 128 {DAY_OF_MONTH, TextStyle.SHORT, 31, "31"}, 129 130 {MONTH_OF_YEAR, TextStyle.FULL, 1, "January"}, 131 {MONTH_OF_YEAR, TextStyle.FULL, 12, "December"}, 132 133 {MONTH_OF_YEAR, TextStyle.SHORT, 1, "Jan"}, 134 {MONTH_OF_YEAR, TextStyle.SHORT, 12, "Dec"}, 135 }; 136 } 137 138 @Test(dataProvider="printText", groups={"tck"}) 139 public void test_appendText2arg_format(TemporalField field, TextStyle style, int value, String expected) throws Exception { 140 DateTimeFormatter f = builder.appendText(field, style).toFormatter(Locale.ENGLISH); 141 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 142 dt = dt.with(field, value); 143 String text = f.format(dt); 144 assertEquals(text, expected); 145 } 146 147 @Test(dataProvider="printText", groups={"tck"}) 148 public void test_appendText1arg_format(TemporalField field, TextStyle style, int value, String expected) throws Exception { 149 if (style == TextStyle.FULL) { 150 DateTimeFormatter f = builder.appendText(field).toFormatter(Locale.ENGLISH); 151 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 152 dt = dt.with(field, value); 153 String text = f.format(dt); 154 assertEquals(text, expected); 155 } 156 } 157 158 //----------------------------------------------------------------------- 159 @Test(groups={"tck"}) 160 public void test_print_appendText2arg_french_long() throws Exception { 161 DateTimeFormatter f = builder.appendText(MONTH_OF_YEAR, TextStyle.FULL).toFormatter(Locale.FRENCH); 162 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 163 String text = f.format(dt); 164 assertEquals(text, "janvier"); 165 } 166 167 @Test(groups={"tck"}) 168 public void test_print_appendText2arg_french_short() throws Exception { 169 DateTimeFormatter f = builder.appendText(MONTH_OF_YEAR, TextStyle.SHORT).toFormatter(Locale.FRENCH); 170 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 171 String text = f.format(dt); 172 assertEquals(text, "janv."); 173 } 174 175 //----------------------------------------------------------------------- 176 @Test(groups={"tck"}) 177 public void test_appendTextMap() throws Exception { 178 Map<Long, String> map = new HashMap<Long, String>(); 179 map.put(1L, "JNY"); 180 map.put(2L, "FBY"); 181 map.put(3L, "MCH"); 182 map.put(4L, "APL"); 183 map.put(5L, "MAY"); 184 map.put(6L, "JUN"); 185 map.put(7L, "JLY"); 186 map.put(8L, "AGT"); 187 map.put(9L, "SPT"); 188 map.put(10L, "OBR"); 189 map.put(11L, "NVR"); 190 map.put(12L, "DBR"); 191 builder.appendText(MONTH_OF_YEAR, map); 192 DateTimeFormatter f = builder.toFormatter(); 193 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 194 for (Month month : Month.values()) { 195 assertEquals(f.format(dt.with(month)), map.get((long) month.getValue())); 196 } 197 } 198 199 @Test(groups={"tck"}) 200 public void test_appendTextMap_DOM() throws Exception { 201 Map<Long, String> map = new HashMap<Long, String>(); 202 map.put(1L, "1st"); 203 map.put(2L, "2nd"); 204 map.put(3L, "3rd"); 205 builder.appendText(DAY_OF_MONTH, map); 206 DateTimeFormatter f = builder.toFormatter(); 207 LocalDateTime dt = LocalDateTime.of(2010, 1, 1, 0, 0); 208 assertEquals(f.format(dt.withDayOfMonth(1)), "1st"); 209 assertEquals(f.format(dt.withDayOfMonth(2)), "2nd"); 210 assertEquals(f.format(dt.withDayOfMonth(3)), "3rd"); 211 } 212 213 @Test(groups={"tck"}) 214 public void test_appendTextMapIncomplete() throws Exception { 215 Map<Long, String> map = new HashMap<Long, String>(); 216 map.put(1L, "JNY"); 217 builder.appendText(MONTH_OF_YEAR, map); 218 DateTimeFormatter f = builder.toFormatter(); 219 LocalDateTime dt = LocalDateTime.of(2010, 2, 1, 0, 0); 220 assertEquals(f.format(dt), "2"); 221 } 222 223 } |