|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2013, 2021, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2013, 2022, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
|
25 | 25 |
|
26 | 26 | package test.javafx.scene.control;
|
27 | 27 |
|
| 28 | +import java.time.DateTimeException; |
28 | 29 | import java.time.LocalDate;
|
29 | 30 | import java.time.chrono.*;
|
| 31 | +import java.time.temporal.ChronoField; |
| 32 | +import java.time.temporal.TemporalAccessor; |
| 33 | +import java.time.temporal.ValueRange; |
30 | 34 | import java.util.*;
|
31 | 35 |
|
32 | 36 | import javafx.scene.control.Button;
|
@@ -620,6 +624,30 @@ public Node getDisplayNode() {
|
620 | 624 | sl.dispose();
|
621 | 625 | }
|
622 | 626 |
|
| 627 | + @Test |
| 628 | + public void testInvalidChronologyIsRestored() { |
| 629 | + datePicker = new DatePicker(LocalDate.of(1998, 1, 23)); |
| 630 | + datePicker.setChronology(IsoChronology.INSTANCE); |
| 631 | + |
| 632 | + assertEquals(IsoChronology.INSTANCE, datePicker.getChronology()); |
| 633 | + |
| 634 | + // This should restore the old set chronology (Iso) as the chronology is invalid. |
| 635 | + datePicker.setChronology(new InvalidChronology()); |
| 636 | + assertEquals(IsoChronology.INSTANCE, datePicker.getChronology()); |
| 637 | + } |
| 638 | + |
| 639 | + @Test |
| 640 | + public void testInvalidValueIsRestored() { |
| 641 | + datePicker = new DatePicker(null); |
| 642 | + assertNull(datePicker.getValue()); |
| 643 | + |
| 644 | + datePicker.setChronology(new InvalidChronology()); |
| 645 | + // This should restore the old set value (null) as the chronology is invalid. |
| 646 | + datePicker.setValue(LocalDate.of(1998, 1, 23)); |
| 647 | + |
| 648 | + assertNull(datePicker.getValue()); |
| 649 | + } |
| 650 | + |
623 | 651 | @Test
|
624 | 652 | public void testCommitValue() {
|
625 | 653 | datePicker.setEditable(true);
|
@@ -709,4 +737,51 @@ public void testFocusLost() {
|
709 | 737 | stageLoader.dispose();
|
710 | 738 | }
|
711 | 739 |
|
| 740 | + private class InvalidChronology extends AbstractChronology { |
| 741 | + @Override |
| 742 | + public String getId() { |
| 743 | + return null; |
| 744 | + } |
| 745 | + @Override |
| 746 | + public String getCalendarType() { |
| 747 | + return null; |
| 748 | + } |
| 749 | + @Override |
| 750 | + public ChronoLocalDate date(int prolepticYear, int month, int dayOfMonth) { |
| 751 | + return null; |
| 752 | + } |
| 753 | + @Override |
| 754 | + public ChronoLocalDate dateYearDay(int prolepticYear, int dayOfYear) { |
| 755 | + return null; |
| 756 | + } |
| 757 | + @Override |
| 758 | + public ChronoLocalDate dateEpochDay(long epochDay) { |
| 759 | + return null; |
| 760 | + } |
| 761 | + @Override |
| 762 | + public ChronoLocalDate date(TemporalAccessor temporal) { |
| 763 | + throw new DateTimeException("Invalid"); |
| 764 | + } |
| 765 | + @Override |
| 766 | + public boolean isLeapYear(long prolepticYear) { |
| 767 | + return false; |
| 768 | + } |
| 769 | + @Override |
| 770 | + public int prolepticYear(Era era, int yearOfEra) { |
| 771 | + return 0; |
| 772 | + } |
| 773 | + @Override |
| 774 | + public Era eraOf(int eraValue) { |
| 775 | + return null; |
| 776 | + } |
| 777 | + @Override |
| 778 | + public List<Era> eras() { |
| 779 | + return null; |
| 780 | + } |
| 781 | + @Override |
| 782 | + public ValueRange range(ChronoField field) { |
| 783 | + return null; |
| 784 | + } |
| 785 | + } |
| 786 | + |
712 | 787 | }
|
0 commit comments