1 16 package org.joda.time; 17 18 import java.util.Locale ; 19 20 import junit.framework.TestCase; 21 import junit.framework.TestSuite; 22 23 import org.joda.time.chrono.CopticChronology; 24 25 30 public class TestLocalDateTime_Properties extends TestCase { 31 32 private static final CopticChronology COPTIC_UTC = CopticChronology.getInstanceUTC(); 33 34 private int MILLIS_OF_DAY = 35 (int) (10L * DateTimeConstants.MILLIS_PER_HOUR 36 + 20L * DateTimeConstants.MILLIS_PER_MINUTE 37 + 30L * DateTimeConstants.MILLIS_PER_SECOND 38 + 40L); 39 private long TEST_TIME_NOW = 40 (31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY 41 + MILLIS_OF_DAY; 42 private long TEST_TIME1 = 43 (31L + 28L + 31L + 6L -1L) * DateTimeConstants.MILLIS_PER_DAY 44 + 1L * DateTimeConstants.MILLIS_PER_HOUR 45 + 2L * DateTimeConstants.MILLIS_PER_MINUTE 46 + 3L * DateTimeConstants.MILLIS_PER_SECOND 47 + 4L; 48 private long TEST_TIME2 = 49 (365L + 31L + 28L + 31L + 30L + 7L -1L) * DateTimeConstants.MILLIS_PER_DAY 50 + 4L * DateTimeConstants.MILLIS_PER_HOUR 51 + 5L * DateTimeConstants.MILLIS_PER_MINUTE 52 + 6L * DateTimeConstants.MILLIS_PER_SECOND 53 + 7L; 54 55 private DateTimeZone zone = null; 56 57 public static void main(String [] args) { 58 junit.textui.TestRunner.run(suite()); 59 } 60 61 public static TestSuite suite() { 62 return new TestSuite(TestLocalDateTime_Properties.class); 63 } 64 65 public TestLocalDateTime_Properties(String name) { 66 super(name); 67 } 68 69 protected void setUp() throws Exception { 70 DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW); 71 zone = DateTimeZone.getDefault(); 72 DateTimeZone.setDefault(DateTimeZone.UTC); 73 } 74 75 protected void tearDown() throws Exception { 76 DateTimeUtils.setCurrentMillisSystem(); 77 DateTimeZone.setDefault(zone); 78 zone = null; 79 } 80 81 public void testPropertyGetYear() { 83 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 84 assertSame(test.getChronology().year(), test.year().getField()); 85 assertEquals("year", test.year().getName()); 86 assertEquals("Property[year]", test.year().toString()); 87 assertSame(test, test.year().getLocalDateTime()); 88 assertEquals(1972, test.year().get()); 89 assertEquals("1972", test.year().getAsString()); 90 assertEquals("1972", test.year().getAsText()); 91 assertEquals("1972", test.year().getAsText(Locale.FRENCH)); 92 assertEquals("1972", test.year().getAsShortText()); 93 assertEquals("1972", test.year().getAsShortText(Locale.FRENCH)); 94 assertEquals(test.getChronology().years(), test.year().getDurationField()); 95 assertEquals(null, test.year().getRangeDurationField()); 96 assertEquals(9, test.year().getMaximumTextLength(null)); 97 assertEquals(9, test.year().getMaximumShortTextLength(null)); 98 } 99 100 public void testPropertyGetMaxMinValuesYear() { 101 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 102 assertEquals(-292275054, test.year().getMinimumValue()); 103 assertEquals(-292275054, test.year().getMinimumValueOverall()); 104 assertEquals(292278993, test.year().getMaximumValue()); 105 assertEquals(292278993, test.year().getMaximumValueOverall()); 106 } 107 108 public void testPropertyAddToCopyYear() { 109 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 110 LocalDateTime copy = test.year().addToCopy(9); 111 check(test, 1972, 6, 9, 10, 20, 30, 40); 112 check(copy, 1981, 6, 9, 10, 20, 30, 40); 113 114 copy = test.year().addToCopy(0); 115 check(copy, 1972, 6, 9, 10, 20, 30, 40); 116 117 copy = test.year().addToCopy(292278993 - 1972); 118 check(copy, 292278993, 6, 9, 10, 20, 30, 40); 119 120 try { 121 test.year().addToCopy(292278993 - 1972 + 1); 122 fail(); 123 } catch (IllegalArgumentException ex) {} 124 check(test, 1972, 6, 9, 10, 20, 30, 40); 125 126 copy = test.year().addToCopy(-1972); 127 check(copy, 0, 6, 9, 10, 20, 30, 40); 128 129 copy = test.year().addToCopy(-1973); 130 check(copy, -1, 6, 9, 10, 20, 30, 40); 131 132 try { 133 test.year().addToCopy(-292275054 - 1972 - 1); 134 fail(); 135 } catch (IllegalArgumentException ex) {} 136 check(test, 1972, 6, 9, 10, 20, 30, 40); 137 } 138 139 public void testPropertyAddWrapFieldToCopyYear() { 140 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 141 LocalDateTime copy = test.year().addWrapFieldToCopy(9); 142 check(test, 1972, 6, 9, 10, 20, 30, 40); 143 check(copy, 1981, 6, 9, 10, 20, 30, 40); 144 145 copy = test.year().addWrapFieldToCopy(0); 146 check(copy, 1972, 6, 9, 10, 20, 30, 40); 147 148 copy = test.year().addWrapFieldToCopy(292278993 - 1972 + 1); 149 check(copy, -292275054, 6, 9, 10, 20, 30, 40); 150 151 copy = test.year().addWrapFieldToCopy(-292275054 - 1972 - 1); 152 check(copy, 292278993, 6, 9, 10, 20, 30, 40); 153 } 154 155 public void testPropertySetCopyYear() { 156 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 157 LocalDateTime copy = test.year().setCopy(12); 158 check(test, 1972, 6, 9, 10, 20, 30, 40); 159 check(copy, 12, 6, 9, 10, 20, 30, 40); 160 } 161 162 public void testPropertySetCopyTextYear() { 163 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 164 LocalDateTime copy = test.year().setCopy("12"); 165 check(test, 1972, 6, 9, 10, 20, 30, 40); 166 check(copy, 12, 6, 9, 10, 20, 30, 40); 167 } 168 169 public void testPropertyCompareToYear() { 170 LocalDateTime test1 = new LocalDateTime(TEST_TIME1); 171 LocalDateTime test2 = new LocalDateTime(TEST_TIME2); 172 assertEquals(true, test1.year().compareTo(test2) < 0); 173 assertEquals(true, test2.year().compareTo(test1) > 0); 174 assertEquals(true, test1.year().compareTo(test1) == 0); 175 try { 176 test1.year().compareTo((ReadablePartial) null); 177 fail(); 178 } catch (IllegalArgumentException ex) {} 179 180 DateTime dt1 = new DateTime(TEST_TIME1); 181 DateTime dt2 = new DateTime(TEST_TIME2); 182 assertEquals(true, test1.year().compareTo(dt2) < 0); 183 assertEquals(true, test2.year().compareTo(dt1) > 0); 184 assertEquals(true, test1.year().compareTo(dt1) == 0); 185 try { 186 test1.year().compareTo((ReadableInstant) null); 187 fail(); 188 } catch (IllegalArgumentException ex) {} 189 } 190 191 public void testPropertyGetMonth() { 193 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 194 assertSame(test.getChronology().monthOfYear(), test.monthOfYear().getField()); 195 assertEquals("monthOfYear", test.monthOfYear().getName()); 196 assertEquals("Property[monthOfYear]", test.monthOfYear().toString()); 197 assertSame(test, test.monthOfYear().getLocalDateTime()); 198 assertEquals(6, test.monthOfYear().get()); 199 assertEquals("6", test.monthOfYear().getAsString()); 200 assertEquals("June", test.monthOfYear().getAsText()); 201 assertEquals("juin", test.monthOfYear().getAsText(Locale.FRENCH)); 202 assertEquals("Jun", test.monthOfYear().getAsShortText()); 203 assertEquals("juin", test.monthOfYear().getAsShortText(Locale.FRENCH)); 204 assertEquals(test.getChronology().months(), test.monthOfYear().getDurationField()); 205 assertEquals(test.getChronology().years(), test.monthOfYear().getRangeDurationField()); 206 assertEquals(9, test.monthOfYear().getMaximumTextLength(null)); 207 assertEquals(3, test.monthOfYear().getMaximumShortTextLength(null)); 208 test = new LocalDateTime(1972, 7, 9, 10, 20, 30, 40); 209 assertEquals("juillet", test.monthOfYear().getAsText(Locale.FRENCH)); 210 assertEquals("juil.", test.monthOfYear().getAsShortText(Locale.FRENCH)); 211 } 212 213 public void testPropertyGetMaxMinValuesMonth() { 214 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 215 assertEquals(1, test.monthOfYear().getMinimumValue()); 216 assertEquals(1, test.monthOfYear().getMinimumValueOverall()); 217 assertEquals(12, test.monthOfYear().getMaximumValue()); 218 assertEquals(12, test.monthOfYear().getMaximumValueOverall()); 219 } 220 221 public void testPropertyAddToCopyMonth() { 222 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 223 LocalDateTime copy = test.monthOfYear().addToCopy(6); 224 check(test, 1972, 6, 9, 10, 20, 30, 40); 225 check(copy, 1972, 12, 9, 10, 20, 30, 40); 226 227 copy = test.monthOfYear().addToCopy(7); 228 check(copy, 1973, 1, 9, 10, 20, 30, 40); 229 230 copy = test.monthOfYear().addToCopy(-5); 231 check(copy, 1972, 1, 9, 10, 20, 30, 40); 232 233 copy = test.monthOfYear().addToCopy(-6); 234 check(copy, 1971, 12, 9, 10, 20, 30, 40); 235 236 test = new LocalDateTime(1972, 1, 31, 10, 20, 30, 40); 237 copy = test.monthOfYear().addToCopy(1); 238 check(copy, 1972, 2, 29, 10, 20, 30, 40); 239 240 copy = test.monthOfYear().addToCopy(2); 241 check(copy, 1972, 3, 31, 10, 20, 30, 40); 242 243 copy = test.monthOfYear().addToCopy(3); 244 check(copy, 1972, 4, 30, 10, 20, 30, 40); 245 246 test = new LocalDateTime(1971, 1, 31, 10, 20, 30, 40); 247 copy = test.monthOfYear().addToCopy(1); 248 check(copy, 1971, 2, 28, 10, 20, 30, 40); 249 } 250 251 public void testPropertyAddWrapFieldToCopyMonth() { 252 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 253 LocalDateTime copy = test.monthOfYear().addWrapFieldToCopy(4); 254 check(test, 1972, 6, 9, 10, 20, 30, 40); 255 check(copy, 1972, 10, 9, 10, 20, 30, 40); 256 257 copy = test.monthOfYear().addWrapFieldToCopy(8); 258 check(copy, 1972, 2, 9, 10, 20, 30, 40); 259 260 copy = test.monthOfYear().addWrapFieldToCopy(-8); 261 check(copy, 1972, 10, 9, 10, 20, 30, 40); 262 263 test = new LocalDateTime(1972, 1, 31, 10, 20, 30, 40); 264 copy = test.monthOfYear().addWrapFieldToCopy(1); 265 check(copy, 1972, 2, 29, 10, 20, 30, 40); 266 267 copy = test.monthOfYear().addWrapFieldToCopy(2); 268 check(copy, 1972, 3, 31, 10, 20, 30, 40); 269 270 copy = test.monthOfYear().addWrapFieldToCopy(3); 271 check(copy, 1972, 4, 30, 10, 20, 30, 40); 272 273 test = new LocalDateTime(1971, 1, 31, 10, 20, 30, 40); 274 copy = test.monthOfYear().addWrapFieldToCopy(1); 275 check(copy, 1971, 2, 28, 10, 20, 30, 40); 276 } 277 278 public void testPropertySetCopyMonth() { 279 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 280 LocalDateTime copy = test.monthOfYear().setCopy(12); 281 check(test, 1972, 6, 9, 10, 20, 30, 40); 282 check(copy, 1972, 12, 9, 10, 20, 30, 40); 283 284 test = new LocalDateTime(1972, 1, 31, 10, 20, 30, 40); 285 copy = test.monthOfYear().setCopy(2); 286 check(copy, 1972, 2, 29, 10, 20, 30, 40); 287 288 try { 289 test.monthOfYear().setCopy(13); 290 fail(); 291 } catch (IllegalArgumentException ex) {} 292 try { 293 test.monthOfYear().setCopy(0); 294 fail(); 295 } catch (IllegalArgumentException ex) {} 296 } 297 298 public void testPropertySetCopyTextMonth() { 299 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 300 LocalDateTime copy = test.monthOfYear().setCopy("12"); 301 check(test, 1972, 6, 9, 10, 20, 30, 40); 302 check(copy, 1972, 12, 9, 10, 20, 30, 40); 303 304 copy = test.monthOfYear().setCopy("December"); 305 check(test, 1972, 6, 9, 10, 20, 30, 40); 306 check(copy, 1972, 12, 9, 10, 20, 30, 40); 307 308 copy = test.monthOfYear().setCopy("Dec"); 309 check(test, 1972, 6, 9, 10, 20, 30, 40); 310 check(copy, 1972, 12, 9, 10, 20, 30, 40); 311 } 312 313 public void testPropertyCompareToMonth() { 314 LocalDateTime test1 = new LocalDateTime(TEST_TIME1); 315 LocalDateTime test2 = new LocalDateTime(TEST_TIME2); 316 assertEquals(true, test1.monthOfYear().compareTo(test2) < 0); 317 assertEquals(true, test2.monthOfYear().compareTo(test1) > 0); 318 assertEquals(true, test1.monthOfYear().compareTo(test1) == 0); 319 try { 320 test1.monthOfYear().compareTo((ReadablePartial) null); 321 fail(); 322 } catch (IllegalArgumentException ex) {} 323 324 DateTime dt1 = new DateTime(TEST_TIME1); 325 DateTime dt2 = new DateTime(TEST_TIME2); 326 assertEquals(true, test1.monthOfYear().compareTo(dt2) < 0); 327 assertEquals(true, test2.monthOfYear().compareTo(dt1) > 0); 328 assertEquals(true, test1.monthOfYear().compareTo(dt1) == 0); 329 try { 330 test1.monthOfYear().compareTo((ReadableInstant) null); 331 fail(); 332 } catch (IllegalArgumentException ex) {} 333 } 334 335 public void testPropertyGetDay() { 337 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 338 assertSame(test.getChronology().dayOfMonth(), test.dayOfMonth().getField()); 339 assertEquals("dayOfMonth", test.dayOfMonth().getName()); 340 assertEquals("Property[dayOfMonth]", test.dayOfMonth().toString()); 341 assertSame(test, test.dayOfMonth().getLocalDateTime()); 342 assertEquals(9, test.dayOfMonth().get()); 343 assertEquals("9", test.dayOfMonth().getAsString()); 344 assertEquals("9", test.dayOfMonth().getAsText()); 345 assertEquals("9", test.dayOfMonth().getAsText(Locale.FRENCH)); 346 assertEquals("9", test.dayOfMonth().getAsShortText()); 347 assertEquals("9", test.dayOfMonth().getAsShortText(Locale.FRENCH)); 348 assertEquals(test.getChronology().days(), test.dayOfMonth().getDurationField()); 349 assertEquals(test.getChronology().months(), test.dayOfMonth().getRangeDurationField()); 350 assertEquals(2, test.dayOfMonth().getMaximumTextLength(null)); 351 assertEquals(2, test.dayOfMonth().getMaximumShortTextLength(null)); 352 } 353 354 public void testPropertyGetMaxMinValuesDay() { 355 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 356 assertEquals(1, test.dayOfMonth().getMinimumValue()); 357 assertEquals(1, test.dayOfMonth().getMinimumValueOverall()); 358 assertEquals(30, test.dayOfMonth().getMaximumValue()); 359 assertEquals(31, test.dayOfMonth().getMaximumValueOverall()); 360 test = new LocalDateTime(1972, 7, 9, 10, 20, 30, 40); 361 assertEquals(31, test.dayOfMonth().getMaximumValue()); 362 test = new LocalDateTime(1972, 2, 9, 10, 20, 30, 40); 363 assertEquals(29, test.dayOfMonth().getMaximumValue()); 364 test = new LocalDateTime(1971, 2, 9, 10, 20, 30, 40); 365 assertEquals(28, test.dayOfMonth().getMaximumValue()); 366 } 367 368 public void testPropertyAddToCopyDay() { 369 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 370 LocalDateTime copy = test.dayOfMonth().addToCopy(9); 371 check(test, 1972, 6, 9, 10, 20, 30, 40); 372 check(copy, 1972, 6, 18, 10, 20, 30, 40); 373 374 copy = test.dayOfMonth().addToCopy(21); 375 check(copy, 1972, 6, 30, 10, 20, 30, 40); 376 377 copy = test.dayOfMonth().addToCopy(22); 378 check(copy, 1972, 7, 1, 10, 20, 30, 40); 379 380 copy = test.dayOfMonth().addToCopy(22 + 30); 381 check(copy, 1972, 7, 31, 10, 20, 30, 40); 382 383 copy = test.dayOfMonth().addToCopy(22 + 31); 384 check(copy, 1972, 8, 1, 10, 20, 30, 40); 385 386 copy = test.dayOfMonth().addToCopy(21 + 31 + 31 + 30 + 31 + 30 + 31); 387 check(copy, 1972, 12, 31, 10, 20, 30, 40); 388 389 copy = test.dayOfMonth().addToCopy(22 + 31 + 31 + 30 + 31 + 30 + 31); 390 check(copy, 1973, 1, 1, 10, 20, 30, 40); 391 392 copy = test.dayOfMonth().addToCopy(-8); 393 check(copy, 1972, 6, 1, 10, 20, 30, 40); 394 395 copy = test.dayOfMonth().addToCopy(-9); 396 check(copy, 1972, 5, 31, 10, 20, 30, 40); 397 398 copy = test.dayOfMonth().addToCopy(-8 - 31 - 30 - 31 - 29 - 31); 399 check(copy, 1972, 1, 1, 10, 20, 30, 40); 400 401 copy = test.dayOfMonth().addToCopy(-9 - 31 - 30 - 31 - 29 - 31); 402 check(copy, 1971, 12, 31, 10, 20, 30, 40); 403 } 404 405 public void testPropertyAddWrapFieldToCopyDay() { 406 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 407 LocalDateTime copy = test.dayOfMonth().addWrapFieldToCopy(21); 408 check(test, 1972, 6, 9, 10, 20, 30, 40); 409 check(copy, 1972, 6, 30, 10, 20, 30, 40); 410 411 copy = test.dayOfMonth().addWrapFieldToCopy(22); 412 check(copy, 1972, 6, 1, 10, 20, 30, 40); 413 414 copy = test.dayOfMonth().addWrapFieldToCopy(-12); 415 check(copy, 1972, 6, 27, 10, 20, 30, 40); 416 417 test = new LocalDateTime(1972, 7, 9, 10, 20, 30, 40); 418 copy = test.dayOfMonth().addWrapFieldToCopy(21); 419 check(copy, 1972, 7, 30, 10, 20, 30, 40); 420 421 copy = test.dayOfMonth().addWrapFieldToCopy(22); 422 check(copy, 1972, 7, 31, 10, 20, 30, 40); 423 424 copy = test.dayOfMonth().addWrapFieldToCopy(23); 425 check(copy, 1972, 7, 1, 10, 20, 30, 40); 426 427 copy = test.dayOfMonth().addWrapFieldToCopy(-12); 428 check(copy, 1972, 7, 28, 10, 20, 30, 40); 429 } 430 431 public void testPropertySetCopyDay() { 432 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 433 LocalDateTime copy = test.dayOfMonth().setCopy(12); 434 check(test, 1972, 6, 9, 10, 20, 30, 40); 435 check(copy, 1972, 6, 12, 10, 20, 30, 40); 436 437 try { 438 test.dayOfMonth().setCopy(31); 439 fail(); 440 } catch (IllegalArgumentException ex) {} 441 try { 442 test.dayOfMonth().setCopy(0); 443 fail(); 444 } catch (IllegalArgumentException ex) {} 445 } 446 447 public void testPropertySetCopyTextDay() { 448 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 449 LocalDateTime copy = test.dayOfMonth().setCopy("12"); 450 check(test, 1972, 6, 9, 10, 20, 30, 40); 451 check(copy, 1972, 6, 12, 10, 20, 30, 40); 452 } 453 454 public void testPropertyWithMaximumValueDayOfMonth() { 455 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 456 LocalDateTime copy = test.dayOfMonth().withMaximumValue(); 457 check(test, 1972, 6, 9, 10, 20, 30, 40); 458 check(copy, 1972, 6, 30, 10, 20, 30, 40); 459 } 460 461 public void testPropertyWithMinimumValueDayOfMonth() { 462 LocalDateTime test = new LocalDateTime(1972, 6, 9, 10, 20, 30, 40); 463 LocalDateTime copy = test.dayOfMonth().withMinimumValue(); 464 check(test, 1972, 6, 9, 10, 20, 30, 40); 465 check(copy, 1972, 6, 1, 10, 20, 30, 40); 466 } 467 468 public void testPropertyCompareToDay() { 469 LocalDateTime test1 = new LocalDateTime(TEST_TIME1); 470 LocalDateTime test2 = new LocalDateTime(TEST_TIME2); 471 assertEquals(true, test1.dayOfMonth().compareTo(test2) < 0); 472 assertEquals(true, test2.dayOfMonth().compareTo(test1) > 0); 473 assertEquals(true, test1.dayOfMonth().compareTo(test1) == 0); 474 try { 475 test1.dayOfMonth().compareTo((ReadablePartial) null); 476 fail(); 477 } catch (IllegalArgumentException ex) {} 478 479 DateTime dt1 = new DateTime(TEST_TIME1); 480 DateTime dt2 = new DateTime(TEST_TIME2); 481 assertEquals(true, test1.dayOfMonth().compareTo(dt2) < 0); 482 assertEquals(true, test2.dayOfMonth().compareTo(dt1) > 0); 483 assertEquals(true, test1.dayOfMonth().compareTo(dt1) == 0); 484 try { 485 test1.dayOfMonth().compareTo((ReadableInstant) null); 486 fail(); 487 } catch (IllegalArgumentException ex) {} 488 } 489 490 public void testPropertyEquals() { 491 LocalDateTime test1 = new LocalDateTime(2005, 11, 8, 10, 20, 30, 40); 492 LocalDateTime test2 = new LocalDateTime(2005, 11, 9, 10, 20, 30, 40); 493 LocalDateTime test3 = new LocalDateTime(2005, 11, 8, 10, 20, 30, 40, COPTIC_UTC); 494 assertEquals(false, test1.dayOfMonth().equals(test1.year())); 495 assertEquals(false, test1.dayOfMonth().equals(test1.monthOfYear())); 496 assertEquals(true, test1.dayOfMonth().equals(test1.dayOfMonth())); 497 assertEquals(false, test1.dayOfMonth().equals(test2.year())); 498 assertEquals(false, test1.dayOfMonth().equals(test2.monthOfYear())); 499 assertEquals(false, test1.dayOfMonth().equals(test2.dayOfMonth())); 500 501 assertEquals(false, test1.monthOfYear().equals(test1.year())); 502 assertEquals(true, test1.monthOfYear().equals(test1.monthOfYear())); 503 assertEquals(false, test1.monthOfYear().equals(test1.dayOfMonth())); 504 assertEquals(false, test1.monthOfYear().equals(test2.year())); 505 assertEquals(true, test1.monthOfYear().equals(test2.monthOfYear())); 506 assertEquals(false, test1.monthOfYear().equals(test2.dayOfMonth())); 507 508 assertEquals(false, test1.dayOfMonth().equals(null)); 509 assertEquals(false, test1.dayOfMonth().equals("any")); 510 511 assertEquals(false, test1.dayOfMonth().equals(test3.dayOfMonth())); 513 } 514 515 public void testPropertyHashCode() { 516 LocalDateTime test1 = new LocalDateTime(2005, 11, 8, 10, 20, 30, 40); 517 LocalDateTime test2 = new LocalDateTime(2005, 11, 9, 10, 20, 30, 40); 518 assertEquals(true, test1.dayOfMonth().hashCode() == test1.dayOfMonth().hashCode()); 519 assertEquals(false, test1.dayOfMonth().hashCode() == test2.dayOfMonth().hashCode()); 520 assertEquals(true, test1.monthOfYear().hashCode() == test1.monthOfYear().hashCode()); 521 assertEquals(true, test1.monthOfYear().hashCode() == test2.monthOfYear().hashCode()); 522 } 523 524 public void testPropertyGetHour() { 526 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 527 assertSame(test.getChronology().hourOfDay(), test.hourOfDay().getField()); 528 assertEquals("hourOfDay", test.hourOfDay().getName()); 529 assertEquals("Property[hourOfDay]", test.hourOfDay().toString()); 530 assertSame(test, test.hourOfDay().getLocalDateTime()); 531 assertEquals(10, test.hourOfDay().get()); 532 assertEquals("10", test.hourOfDay().getAsString()); 533 assertEquals("10", test.hourOfDay().getAsText()); 534 assertEquals("10", test.hourOfDay().getAsText(Locale.FRENCH)); 535 assertEquals("10", test.hourOfDay().getAsShortText()); 536 assertEquals("10", test.hourOfDay().getAsShortText(Locale.FRENCH)); 537 assertEquals(test.getChronology().hours(), test.hourOfDay().getDurationField()); 538 assertEquals(test.getChronology().days(), test.hourOfDay().getRangeDurationField()); 539 assertEquals(2, test.hourOfDay().getMaximumTextLength(null)); 540 assertEquals(2, test.hourOfDay().getMaximumShortTextLength(null)); 541 } 542 543 public void testPropertyRoundHour() { 544 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20); 545 check(test.hourOfDay().roundCeilingCopy(), 2005, 6, 9, 11, 0, 0, 0); 546 check(test.hourOfDay().roundFloorCopy(), 2005, 6, 9, 10, 0, 0, 0); 547 check(test.hourOfDay().roundHalfCeilingCopy(), 2005, 6, 9, 10, 0, 0, 0); 548 check(test.hourOfDay().roundHalfFloorCopy(), 2005, 6, 9, 10, 0, 0, 0); 549 check(test.hourOfDay().roundHalfEvenCopy(), 2005, 6, 9, 10, 0, 0, 0); 550 551 test = new LocalDateTime(2005, 6, 9, 10, 40); 552 check(test.hourOfDay().roundCeilingCopy(), 2005, 6, 9, 11, 0, 0, 0); 553 check(test.hourOfDay().roundFloorCopy(), 2005, 6, 9, 10, 0, 0, 0); 554 check(test.hourOfDay().roundHalfCeilingCopy(), 2005, 6, 9, 11, 0, 0, 0); 555 check(test.hourOfDay().roundHalfFloorCopy(), 2005, 6, 9, 11, 0, 0, 0); 556 check(test.hourOfDay().roundHalfEvenCopy(), 2005, 6, 9, 11, 0, 0, 0); 557 558 test = new LocalDateTime(2005, 6, 9, 10, 30); 559 check(test.hourOfDay().roundCeilingCopy(), 2005, 6, 9, 11, 0, 0, 0); 560 check(test.hourOfDay().roundFloorCopy(), 2005, 6, 9, 10, 0, 0, 0); 561 check(test.hourOfDay().roundHalfCeilingCopy(), 2005, 6, 9, 11, 0, 0, 0); 562 check(test.hourOfDay().roundHalfFloorCopy(), 2005, 6, 9, 10, 0, 0, 0); 563 check(test.hourOfDay().roundHalfEvenCopy(), 2005, 6, 9, 10, 0, 0, 0); 564 565 test = new LocalDateTime(2005, 6, 9, 11, 30); 566 check(test.hourOfDay().roundCeilingCopy(), 2005, 6, 9, 12, 0, 0, 0); 567 check(test.hourOfDay().roundFloorCopy(), 2005, 6, 9, 11, 0, 0, 0); 568 check(test.hourOfDay().roundHalfCeilingCopy(), 2005, 6, 9, 12, 0, 0, 0); 569 check(test.hourOfDay().roundHalfFloorCopy(), 2005, 6, 9, 11, 0, 0, 0); 570 check(test.hourOfDay().roundHalfEvenCopy(), 2005, 6, 9, 12, 0, 0, 0); 571 } 572 573 public void testPropertyGetMaxMinValuesHour() { 574 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 575 assertEquals(0, test.hourOfDay().getMinimumValue()); 576 assertEquals(0, test.hourOfDay().getMinimumValueOverall()); 577 assertEquals(23, test.hourOfDay().getMaximumValue()); 578 assertEquals(23, test.hourOfDay().getMaximumValueOverall()); 579 } 580 581 public void testPropertyWithMaxMinValueHour() { 582 LocalDateTime test = new LocalDateTime(2005, 6, 9, 0, 20, 30, 40); 583 check(test.hourOfDay().withMaximumValue(), 2005, 6, 9, 23, 20, 30, 40); 584 check(test.hourOfDay().withMinimumValue(), 2005, 6, 9, 0, 20, 30, 40); 585 } 586 587 public void testPropertyAddToCopyHour() { 588 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 589 LocalDateTime copy = test.hourOfDay().addToCopy(9); 590 check(test, 2005, 6, 9, 10, 20, 30, 40); 591 check(copy, 2005, 6, 9, 19, 20, 30, 40); 592 593 copy = test.hourOfDay().addToCopy(0); 594 check(copy, 2005, 6, 9, 10, 20, 30, 40); 595 596 copy = test.hourOfDay().addToCopy(13); 597 check(copy, 2005, 6, 9, 23, 20, 30, 40); 598 599 copy = test.hourOfDay().addToCopy(14); 600 check(copy, 2005, 6, 10, 0, 20, 30, 40); 601 602 copy = test.hourOfDay().addToCopy(-10); 603 check(copy, 2005, 6, 9, 0, 20, 30, 40); 604 605 copy = test.hourOfDay().addToCopy(-11); 606 check(copy, 2005, 6, 8, 23, 20, 30, 40); 607 } 608 609 public void testPropertyAddWrapFieldToCopyHour() { 610 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 611 LocalDateTime copy = test.hourOfDay().addWrapFieldToCopy(9); 612 check(test, 2005, 6, 9, 10, 20, 30, 40); 613 check(copy, 2005, 6, 9, 19, 20, 30, 40); 614 615 copy = test.hourOfDay().addWrapFieldToCopy(0); 616 check(copy, 2005, 6, 9, 10, 20, 30, 40); 617 618 copy = test.hourOfDay().addWrapFieldToCopy(18); 619 check(copy, 2005, 6, 9, 4, 20, 30, 40); 620 621 copy = test.hourOfDay().addWrapFieldToCopy(-15); 622 check(copy, 2005, 6, 9, 19, 20, 30, 40); 623 } 624 625 public void testPropertySetHour() { 626 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 627 LocalDateTime copy = test.hourOfDay().setCopy(12); 628 check(test, 2005, 6, 9, 10, 20, 30, 40); 629 check(copy, 2005, 6, 9, 12, 20, 30, 40); 630 631 try { 632 test.hourOfDay().setCopy(24); 633 fail(); 634 } catch (IllegalArgumentException ex) {} 635 try { 636 test.hourOfDay().setCopy(-1); 637 fail(); 638 } catch (IllegalArgumentException ex) {} 639 } 640 641 public void testPropertySetTextHour() { 642 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 643 LocalDateTime copy = test.hourOfDay().setCopy("12"); 644 check(test, 2005, 6, 9, 10, 20, 30, 40); 645 check(copy, 2005, 6, 9, 12, 20, 30, 40); 646 } 647 648 public void testPropertyWithMaximumValueHour() { 649 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 650 LocalDateTime copy = test.hourOfDay().withMaximumValue(); 651 check(test, 2005, 6, 9, 10, 20, 30, 40); 652 check(copy, 2005, 6, 9, 23, 20, 30, 40); 653 } 654 655 public void testPropertyWithMinimumValueHour() { 656 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 657 LocalDateTime copy = test.hourOfDay().withMinimumValue(); 658 check(test, 2005, 6, 9, 10, 20, 30, 40); 659 check(copy, 2005, 6, 9, 0, 20, 30, 40); 660 } 661 662 public void testPropertyCompareToHour() { 663 LocalDateTime test1 = new LocalDateTime(TEST_TIME1); 664 LocalDateTime test2 = new LocalDateTime(TEST_TIME2); 665 assertEquals(true, test1.hourOfDay().compareTo(test2) < 0); 666 assertEquals(true, test2.hourOfDay().compareTo(test1) > 0); 667 assertEquals(true, test1.hourOfDay().compareTo(test1) == 0); 668 try { 669 test1.hourOfDay().compareTo((ReadablePartial) null); 670 fail(); 671 } catch (IllegalArgumentException ex) {} 672 673 DateTime dt1 = new DateTime(TEST_TIME1); 674 DateTime dt2 = new DateTime(TEST_TIME2); 675 assertEquals(true, test1.hourOfDay().compareTo(dt2) < 0); 676 assertEquals(true, test2.hourOfDay().compareTo(dt1) > 0); 677 assertEquals(true, test1.hourOfDay().compareTo(dt1) == 0); 678 try { 679 test1.hourOfDay().compareTo((ReadableInstant) null); 680 fail(); 681 } catch (IllegalArgumentException ex) {} 682 } 683 684 public void testPropertyGetMinute() { 686 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 687 assertSame(test.getChronology().minuteOfHour(), test.minuteOfHour().getField()); 688 assertEquals("minuteOfHour", test.minuteOfHour().getName()); 689 assertEquals("Property[minuteOfHour]", test.minuteOfHour().toString()); 690 assertSame(test, test.minuteOfHour().getLocalDateTime()); 691 assertEquals(20, test.minuteOfHour().get()); 692 assertEquals("20", test.minuteOfHour().getAsString()); 693 assertEquals("20", test.minuteOfHour().getAsText()); 694 assertEquals("20", test.minuteOfHour().getAsText(Locale.FRENCH)); 695 assertEquals("20", test.minuteOfHour().getAsShortText()); 696 assertEquals("20", test.minuteOfHour().getAsShortText(Locale.FRENCH)); 697 assertEquals(test.getChronology().minutes(), test.minuteOfHour().getDurationField()); 698 assertEquals(test.getChronology().hours(), test.minuteOfHour().getRangeDurationField()); 699 assertEquals(2, test.minuteOfHour().getMaximumTextLength(null)); 700 assertEquals(2, test.minuteOfHour().getMaximumShortTextLength(null)); 701 } 702 703 public void testPropertyGetMaxMinValuesMinute() { 704 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 705 assertEquals(0, test.minuteOfHour().getMinimumValue()); 706 assertEquals(0, test.minuteOfHour().getMinimumValueOverall()); 707 assertEquals(59, test.minuteOfHour().getMaximumValue()); 708 assertEquals(59, test.minuteOfHour().getMaximumValueOverall()); 709 } 710 711 public void testPropertyWithMaxMinValueMinute() { 712 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 713 check(test.minuteOfHour().withMaximumValue(), 2005, 6, 9, 10, 59, 30, 40); 714 check(test.minuteOfHour().withMinimumValue(), 2005, 6, 9, 10, 0, 30, 40); 715 } 716 717 public void testPropertyAddToCopyMinute() { 718 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 719 LocalDateTime copy = test.minuteOfHour().addToCopy(9); 720 check(test, 2005, 6, 9, 10, 20, 30, 40); 721 check(copy, 2005, 6, 9, 10, 29, 30, 40); 722 723 copy = test.minuteOfHour().addToCopy(39); 724 check(copy, 2005, 6, 9, 10, 59, 30, 40); 725 726 copy = test.minuteOfHour().addToCopy(40); 727 check(copy, 2005, 6, 9, 11, 0, 30, 40); 728 729 copy = test.minuteOfHour().addToCopy(1 * 60 + 45); 730 check(copy, 2005, 6, 9, 12, 5, 30, 40); 731 732 copy = test.minuteOfHour().addToCopy(13 * 60 + 39); 733 check(copy, 2005, 6, 9, 23, 59, 30, 40); 734 735 copy = test.minuteOfHour().addToCopy(13 * 60 + 40); 736 check(copy, 2005, 6, 10, 0, 0, 30, 40); 737 738 copy = test.minuteOfHour().addToCopy(-9); 739 check(copy, 2005, 6, 9, 10, 11, 30, 40); 740 741 copy = test.minuteOfHour().addToCopy(-19); 742 check(copy, 2005, 6, 9, 10, 1, 30, 40); 743 744 copy = test.minuteOfHour().addToCopy(-20); 745 check(copy, 2005, 6, 9, 10, 0, 30, 40); 746 747 copy = test.minuteOfHour().addToCopy(-21); 748 check(copy, 2005, 6, 9, 9, 59, 30, 40); 749 750 copy = test.minuteOfHour().addToCopy(-(10 * 60 + 20)); 751 check(copy, 2005, 6, 9, 0, 0, 30, 40); 752 753 copy = test.minuteOfHour().addToCopy(-(10 * 60 + 21)); 754 check(copy, 2005, 6, 8, 23, 59, 30, 40); 755 } 756 757 public void testPropertyAddWrapFieldToCopyMinute() { 758 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 759 LocalDateTime copy = test.minuteOfHour().addWrapFieldToCopy(9); 760 check(test, 2005, 6, 9, 10, 20, 30, 40); 761 check(copy, 2005, 6, 9, 10, 29, 30, 40); 762 763 copy = test.minuteOfHour().addWrapFieldToCopy(49); 764 check(copy, 2005, 6, 9, 10, 9, 30, 40); 765 766 copy = test.minuteOfHour().addWrapFieldToCopy(-47); 767 check(copy, 2005, 6, 9, 10, 33, 30, 40); 768 } 769 770 public void testPropertySetMinute() { 771 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 772 LocalDateTime copy = test.minuteOfHour().setCopy(12); 773 check(test, 2005, 6, 9, 10, 20, 30, 40); 774 check(copy, 2005, 6, 9, 10, 12, 30, 40); 775 776 try { 777 test.minuteOfHour().setCopy(60); 778 fail(); 779 } catch (IllegalArgumentException ex) {} 780 try { 781 test.minuteOfHour().setCopy(-1); 782 fail(); 783 } catch (IllegalArgumentException ex) {} 784 } 785 786 public void testPropertySetTextMinute() { 787 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 788 LocalDateTime copy = test.minuteOfHour().setCopy("12"); 789 check(test, 2005, 6, 9, 10, 20, 30, 40); 790 check(copy, 2005, 6, 9, 10, 12, 30, 40); 791 } 792 793 public void testPropertyCompareToMinute() { 794 LocalDateTime test1 = new LocalDateTime(TEST_TIME1); 795 LocalDateTime test2 = new LocalDateTime(TEST_TIME2); 796 assertEquals(true, test1.minuteOfHour().compareTo(test2) < 0); 797 assertEquals(true, test2.minuteOfHour().compareTo(test1) > 0); 798 assertEquals(true, test1.minuteOfHour().compareTo(test1) == 0); 799 try { 800 test1.minuteOfHour().compareTo((ReadablePartial) null); 801 fail(); 802 } catch (IllegalArgumentException ex) {} 803 804 DateTime dt1 = new DateTime(TEST_TIME1); 805 DateTime dt2 = new DateTime(TEST_TIME2); 806 assertEquals(true, test1.minuteOfHour().compareTo(dt2) < 0); 807 assertEquals(true, test2.minuteOfHour().compareTo(dt1) > 0); 808 assertEquals(true, test1.minuteOfHour().compareTo(dt1) == 0); 809 try { 810 test1.minuteOfHour().compareTo((ReadableInstant) null); 811 fail(); 812 } catch (IllegalArgumentException ex) {} 813 } 814 815 public void testPropertyGetSecond() { 817 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 818 assertSame(test.getChronology().secondOfMinute(), test.secondOfMinute().getField()); 819 assertEquals("secondOfMinute", test.secondOfMinute().getName()); 820 assertEquals("Property[secondOfMinute]", test.secondOfMinute().toString()); 821 assertSame(test, test.secondOfMinute().getLocalDateTime()); 822 assertEquals(30, test.secondOfMinute().get()); 823 assertEquals("30", test.secondOfMinute().getAsString()); 824 assertEquals("30", test.secondOfMinute().getAsText()); 825 assertEquals("30", test.secondOfMinute().getAsText(Locale.FRENCH)); 826 assertEquals("30", test.secondOfMinute().getAsShortText()); 827 assertEquals("30", test.secondOfMinute().getAsShortText(Locale.FRENCH)); 828 assertEquals(test.getChronology().seconds(), test.secondOfMinute().getDurationField()); 829 assertEquals(test.getChronology().minutes(), test.secondOfMinute().getRangeDurationField()); 830 assertEquals(2, test.secondOfMinute().getMaximumTextLength(null)); 831 assertEquals(2, test.secondOfMinute().getMaximumShortTextLength(null)); 832 } 833 834 public void testPropertyGetMaxMinValuesSecond() { 835 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 836 assertEquals(0, test.secondOfMinute().getMinimumValue()); 837 assertEquals(0, test.secondOfMinute().getMinimumValueOverall()); 838 assertEquals(59, test.secondOfMinute().getMaximumValue()); 839 assertEquals(59, test.secondOfMinute().getMaximumValueOverall()); 840 } 841 842 public void testPropertyWithMaxMinValueSecond() { 843 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 844 check(test.secondOfMinute().withMaximumValue(), 2005, 6, 9, 10, 20, 59, 40); 845 check(test.secondOfMinute().withMinimumValue(), 2005, 6, 9, 10, 20, 0, 40); 846 } 847 848 public void testPropertyAddToCopySecond() { 849 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 850 LocalDateTime copy = test.secondOfMinute().addToCopy(9); 851 check(test, 2005, 6, 9, 10, 20, 30, 40); 852 check(copy, 2005, 6, 9, 10, 20, 39, 40); 853 854 copy = test.secondOfMinute().addToCopy(29); 855 check(copy, 2005, 6, 9, 10, 20, 59, 40); 856 857 copy = test.secondOfMinute().addToCopy(30); 858 check(copy, 2005, 6, 9, 10, 21, 0, 40); 859 860 copy = test.secondOfMinute().addToCopy(39 * 60 + 29); 861 check(copy, 2005, 6, 9, 10, 59, 59, 40); 862 863 copy = test.secondOfMinute().addToCopy(39 * 60 + 30); 864 check(copy, 2005, 6, 9, 11, 0, 0, 40); 865 866 copy = test.secondOfMinute().addToCopy(13 * 60 * 60 + 39 * 60 + 30); 867 check(copy, 2005, 6, 10, 0, 0, 0, 40); 868 869 copy = test.secondOfMinute().addToCopy(-9); 870 check(copy, 2005, 6, 9, 10, 20, 21, 40); 871 872 copy = test.secondOfMinute().addToCopy(-30); 873 check(copy, 2005, 6, 9, 10, 20, 0, 40); 874 875 copy = test.secondOfMinute().addToCopy(-31); 876 check(copy, 2005, 6, 9, 10, 19, 59, 40); 877 878 copy = test.secondOfMinute().addToCopy(-(10 * 60 * 60 + 20 * 60 + 30)); 879 check(copy, 2005, 6, 9, 0, 0, 0, 40); 880 881 copy = test.secondOfMinute().addToCopy(-(10 * 60 * 60 + 20 * 60 + 31)); 882 check(copy, 2005, 6, 8, 23, 59, 59, 40); 883 } 884 885 public void testPropertyAddWrapFieldToCopySecond() { 886 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 887 LocalDateTime copy = test.secondOfMinute().addWrapFieldToCopy(9); 888 check(test, 2005, 6, 9, 10, 20, 30, 40); 889 check(copy, 2005, 6, 9, 10, 20, 39, 40); 890 891 copy = test.secondOfMinute().addWrapFieldToCopy(49); 892 check(copy, 2005, 6, 9, 10, 20, 19, 40); 893 894 copy = test.secondOfMinute().addWrapFieldToCopy(-47); 895 check(copy, 2005, 6, 9, 10, 20, 43, 40); 896 } 897 898 public void testPropertySetSecond() { 899 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 900 LocalDateTime copy = test.secondOfMinute().setCopy(12); 901 check(test, 2005, 6, 9, 10, 20, 30, 40); 902 check(copy, 2005, 6, 9, 10, 20, 12, 40); 903 904 try { 905 test.secondOfMinute().setCopy(60); 906 fail(); 907 } catch (IllegalArgumentException ex) {} 908 try { 909 test.secondOfMinute().setCopy(-1); 910 fail(); 911 } catch (IllegalArgumentException ex) {} 912 } 913 914 public void testPropertySetTextSecond() { 915 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 916 LocalDateTime copy = test.secondOfMinute().setCopy("12"); 917 check(test, 2005, 6, 9, 10, 20, 30, 40); 918 check(copy, 2005, 6, 9, 10, 20, 12, 40); 919 } 920 921 public void testPropertyCompareToSecond() { 922 LocalDateTime test1 = new LocalDateTime(TEST_TIME1); 923 LocalDateTime test2 = new LocalDateTime(TEST_TIME2); 924 assertEquals(true, test1.secondOfMinute().compareTo(test2) < 0); 925 assertEquals(true, test2.secondOfMinute().compareTo(test1) > 0); 926 assertEquals(true, test1.secondOfMinute().compareTo(test1) == 0); 927 try { 928 test1.secondOfMinute().compareTo((ReadablePartial) null); 929 fail(); 930 } catch (IllegalArgumentException ex) {} 931 932 DateTime dt1 = new DateTime(TEST_TIME1); 933 DateTime dt2 = new DateTime(TEST_TIME2); 934 assertEquals(true, test1.secondOfMinute().compareTo(dt2) < 0); 935 assertEquals(true, test2.secondOfMinute().compareTo(dt1) > 0); 936 assertEquals(true, test1.secondOfMinute().compareTo(dt1) == 0); 937 try { 938 test1.secondOfMinute().compareTo((ReadableInstant) null); 939 fail(); 940 } catch (IllegalArgumentException ex) {} 941 } 942 943 public void testPropertyGetMilli() { 945 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 946 assertSame(test.getChronology().millisOfSecond(), test.millisOfSecond().getField()); 947 assertEquals("millisOfSecond", test.millisOfSecond().getName()); 948 assertEquals("Property[millisOfSecond]", test.millisOfSecond().toString()); 949 assertSame(test, test.millisOfSecond().getLocalDateTime()); 950 assertEquals(40, test.millisOfSecond().get()); 951 assertEquals("40", test.millisOfSecond().getAsString()); 952 assertEquals("40", test.millisOfSecond().getAsText()); 953 assertEquals("40", test.millisOfSecond().getAsText(Locale.FRENCH)); 954 assertEquals("40", test.millisOfSecond().getAsShortText()); 955 assertEquals("40", test.millisOfSecond().getAsShortText(Locale.FRENCH)); 956 assertEquals(test.getChronology().millis(), test.millisOfSecond().getDurationField()); 957 assertEquals(test.getChronology().seconds(), test.millisOfSecond().getRangeDurationField()); 958 assertEquals(3, test.millisOfSecond().getMaximumTextLength(null)); 959 assertEquals(3, test.millisOfSecond().getMaximumShortTextLength(null)); 960 } 961 962 public void testPropertyGetMaxMinValuesMilli() { 963 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 964 assertEquals(0, test.millisOfSecond().getMinimumValue()); 965 assertEquals(0, test.millisOfSecond().getMinimumValueOverall()); 966 assertEquals(999, test.millisOfSecond().getMaximumValue()); 967 assertEquals(999, test.millisOfSecond().getMaximumValueOverall()); 968 } 969 970 public void testPropertyWithMaxMinValueMilli() { 971 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 972 check(test.millisOfSecond().withMaximumValue(), 2005, 6, 9, 10, 20, 30, 999); 973 check(test.millisOfSecond().withMinimumValue(), 2005, 6, 9, 10, 20, 30, 0); 974 } 975 976 public void testPropertyAddToCopyMilli() { 977 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 978 LocalDateTime copy = test.millisOfSecond().addToCopy(9); 979 check(test, 2005, 6, 9, 10, 20, 30, 40); 980 check(copy, 2005, 6, 9, 10, 20, 30, 49); 981 982 copy = test.millisOfSecond().addToCopy(959); 983 check(copy, 2005, 6, 9, 10, 20, 30, 999); 984 985 copy = test.millisOfSecond().addToCopy(960); 986 check(copy, 2005, 6, 9, 10, 20, 31, 0); 987 988 copy = test.millisOfSecond().addToCopy(13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 959); 989 check(copy, 2005, 6, 9, 23, 59, 59, 999); 990 991 copy = test.millisOfSecond().addToCopy(13 * 60 * 60 * 1000 + 39 * 60 * 1000 + 29 * 1000 + 960); 992 check(copy, 2005, 6, 10, 0, 0, 0, 0); 993 994 copy = test.millisOfSecond().addToCopy(-9); 995 check(copy, 2005, 6, 9, 10, 20, 30, 31); 996 997 copy = test.millisOfSecond().addToCopy(-40); 998 check(copy, 2005, 6, 9, 10, 20, 30, 0); 999 1000 copy = test.millisOfSecond().addToCopy(-41); 1001 check(copy, 2005, 6, 9, 10, 20, 29, 999); 1002 1003 copy = test.millisOfSecond().addToCopy(-(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30 * 1000 + 40)); 1004 check(copy, 2005, 6, 9, 0, 0, 0, 0); 1005 1006 copy = test.millisOfSecond().addToCopy(-(10 * 60 * 60 * 1000 + 20 * 60 * 1000 + 30 * 1000 + 41)); 1007 check(copy, 2005, 6, 8, 23, 59, 59, 999); 1008 } 1009 1010 public void testPropertyAddWrapFieldToCopyMilli() { 1011 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 1012 LocalDateTime copy = test.millisOfSecond().addWrapFieldToCopy(9); 1013 check(test, 2005, 6, 9, 10, 20, 30, 40); 1014 check(copy, 2005, 6, 9, 10, 20, 30, 49); 1015 1016 copy = test.millisOfSecond().addWrapFieldToCopy(995); 1017 check(copy, 2005, 6, 9, 10, 20, 30, 35); 1018 1019 copy = test.millisOfSecond().addWrapFieldToCopy(-47); 1020 check(copy, 2005, 6, 9, 10, 20, 30, 993); 1021 } 1022 1023 public void testPropertySetMilli() { 1024 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 1025 LocalDateTime copy = test.millisOfSecond().setCopy(12); 1026 check(test, 2005, 6, 9, 10, 20, 30, 40); 1027 check(copy, 2005, 6, 9, 10, 20, 30, 12); 1028 1029 try { 1030 test.millisOfSecond().setCopy(1000); 1031 fail(); 1032 } catch (IllegalArgumentException ex) {} 1033 try { 1034 test.millisOfSecond().setCopy(-1); 1035 fail(); 1036 } catch (IllegalArgumentException ex) {} 1037 } 1038 1039 public void testPropertySetTextMilli() { 1040 LocalDateTime test = new LocalDateTime(2005, 6, 9, 10, 20, 30, 40); 1041 LocalDateTime copy = test.millisOfSecond().setCopy("12"); 1042 check(test, 2005, 6, 9, 10, 20, 30, 40); 1043 check(copy, 2005, 6, 9, 10, 20, 30, 12); 1044 } 1045 1046 public void testPropertyCompareToMilli() { 1047 LocalDateTime test1 = new LocalDateTime(TEST_TIME1); 1048 LocalDateTime test2 = new LocalDateTime(TEST_TIME2); 1049 assertEquals(true, test1.millisOfSecond().compareTo(test2) < 0); 1050 assertEquals(true, test2.millisOfSecond().compareTo(test1) > 0); 1051 assertEquals(true, test1.millisOfSecond().compareTo(test1) == 0); 1052 try { 1053 test1.millisOfSecond().compareTo((ReadablePartial) null); 1054 fail(); 1055 } catch (IllegalArgumentException ex) {} 1056 1057 DateTime dt1 = new DateTime(TEST_TIME1); 1058 DateTime dt2 = new DateTime(TEST_TIME2); 1059 assertEquals(true, test1.millisOfSecond().compareTo(dt2) < 0); 1060 assertEquals(true, test2.millisOfSecond().compareTo(dt1) > 0); 1061 assertEquals(true, test1.millisOfSecond().compareTo(dt1) == 0); 1062 try { 1063 test1.millisOfSecond().compareTo((ReadableInstant) null); 1064 fail(); 1065 } catch (IllegalArgumentException ex) {} 1066 } 1067 1068 private void check(LocalDateTime test, int year, int month, int day, int hour, int min, int sec, int mil) { 1070 assertEquals(year, test.getYear()); 1071 assertEquals(month, test.getMonthOfYear()); 1072 assertEquals(day, test.getDayOfMonth()); 1073 assertEquals(hour, test.getHourOfDay()); 1074 assertEquals(min, test.getMinuteOfHour()); 1075 assertEquals(sec, test.getSecondOfMinute()); 1076 assertEquals(mil, test.getMillisOfSecond()); 1077 } 1078} 1079 | Popular Tags |