test/java/time/tck/java/time/TCKMonthDay.java
Print this page
*** 55,104 ****
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
! package tck.java.time.temporal;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.HashSet;
- import java.util.List;
- import java.util.Set;
-
import java.time.Clock;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
- import java.time.format.DateTimeFormatters;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
import java.time.temporal.JulianFields;
! import java.time.temporal.MonthDay;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
! import java.time.temporal.YearMonth;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
- import tck.java.time.AbstractDateTimeTest;
/**
* Test MonthDay.
*/
@Test
--- 55,104 ----
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
! package tck.java.time;
import static java.time.temporal.ChronoField.DAY_OF_MONTH;
import static java.time.temporal.ChronoField.MONTH_OF_YEAR;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.time.Clock;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
+ import java.time.MonthDay;
+ import java.time.YearMonth;
import java.time.ZoneId;
import java.time.ZoneOffset;
+ import java.time.chrono.IsoChronology;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoField;
import java.time.temporal.JulianFields;
! import java.time.temporal.Queries;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalField;
! import java.time.temporal.TemporalQuery;
! import java.util.ArrayList;
! import java.util.Arrays;
! import java.util.HashSet;
! import java.util.List;
! import java.util.Set;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
* Test MonthDay.
*/
@Test
*** 145,155 ****
@Test
public void test_serialization_format() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DataOutputStream dos = new DataOutputStream(baos) ) {
! dos.writeByte(6);
dos.writeByte(9);
dos.writeByte(16);
}
byte[] bytes = baos.toByteArray();
assertSerializedBySer(MonthDay.of(9, 16), bytes);
--- 145,155 ----
@Test
public void test_serialization_format() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DataOutputStream dos = new DataOutputStream(baos) ) {
! dos.writeByte(13); // java.time.temporal.Ser.MONTH_DAY_TYPE
dos.writeByte(9);
dos.writeByte(16);
}
byte[] bytes = baos.toByteArray();
assertSerializedBySer(MonthDay.of(9, 16), bytes);
*** 370,387 ****
//-----------------------------------------------------------------------
// parse(DateTimeFormatter)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void factory_parse_formatter() {
! DateTimeFormatter f = DateTimeFormatters.pattern("M d");
MonthDay test = MonthDay.parse("12 3", f);
assertEquals(test, MonthDay.of(12, 3));
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void factory_parse_formatter_nullText() {
! DateTimeFormatter f = DateTimeFormatters.pattern("M d");
MonthDay.parse((String) null, f);
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void factory_parse_formatter_nullFormatter() {
--- 370,387 ----
//-----------------------------------------------------------------------
// parse(DateTimeFormatter)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void factory_parse_formatter() {
! DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
MonthDay test = MonthDay.parse("12 3", f);
assertEquals(test, MonthDay.of(12, 3));
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void factory_parse_formatter_nullText() {
! DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
MonthDay.parse((String) null, f);
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
public void factory_parse_formatter_nullFormatter() {
*** 402,411 ****
--- 402,442 ----
assertEquals(TEST_07_15.getLong(ChronoField.DAY_OF_MONTH), 15);
assertEquals(TEST_07_15.getLong(ChronoField.MONTH_OF_YEAR), 7);
}
//-----------------------------------------------------------------------
+ // query(TemporalQuery)
+ //-----------------------------------------------------------------------
+ @DataProvider(name="query")
+ Object[][] data_query() {
+ return new Object[][] {
+ {TEST_07_15, Queries.chronology(), IsoChronology.INSTANCE},
+ {TEST_07_15, Queries.zoneId(), null},
+ {TEST_07_15, Queries.precision(), null},
+ {TEST_07_15, Queries.zone(), null},
+ {TEST_07_15, Queries.offset(), null},
+ {TEST_07_15, Queries.localDate(), null},
+ {TEST_07_15, Queries.localTime(), null},
+ };
+ }
+
+ @Test(dataProvider="query")
+ public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
+ assertEquals(temporal.query(query), expected);
+ }
+
+ @Test(dataProvider="query")
+ public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
+ assertEquals(query.queryFrom(temporal), expected);
+ }
+
+ @Test(expectedExceptions=NullPointerException.class)
+ public void test_query_null() {
+ TEST_07_15.query(null);
+ }
+
+ //-----------------------------------------------------------------------
// get*()
//-----------------------------------------------------------------------
@DataProvider(name="sampleDates")
Object[][] provider_sampleDates() {
return new Object[][] {
*** 417,430 ****
{7, 4},
{7, 5},
};
}
! @Test(dataProvider="sampleDates", groups={"tck"})
public void test_get(int m, int d) {
MonthDay a = MonthDay.of(m, d);
assertEquals(a.getMonth(), Month.of(m));
assertEquals(a.getDayOfMonth(), d);
}
//-----------------------------------------------------------------------
// with(Month)
--- 448,462 ----
{7, 4},
{7, 5},
};
}
! @Test(dataProvider="sampleDates")
public void test_get(int m, int d) {
MonthDay a = MonthDay.of(m, d);
assertEquals(a.getMonth(), Month.of(m));
+ assertEquals(a.getMonthValue(), m);
assertEquals(a.getDayOfMonth(), d);
}
//-----------------------------------------------------------------------
// with(Month)
*** 741,751 ****
//-----------------------------------------------------------------------
// toString(DateTimeFormatter)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_toString_formatter() {
! DateTimeFormatter f = DateTimeFormatters.pattern("M d");
String t = MonthDay.of(12, 3).toString(f);
assertEquals(t, "12 3");
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})
--- 773,783 ----
//-----------------------------------------------------------------------
// toString(DateTimeFormatter)
//-----------------------------------------------------------------------
@Test(groups={"tck"})
public void test_toString_formatter() {
! DateTimeFormatter f = DateTimeFormatter.ofPattern("M d");
String t = MonthDay.of(12, 3).toString(f);
assertEquals(t, "12 3");
}
@Test(expectedExceptions=NullPointerException.class, groups={"tck"})