test/java/time/tck/java/time/TCKDayOfWeek.java

Print this page




  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import static java.time.DayOfWeek.MONDAY;
  63 import static java.time.DayOfWeek.SUNDAY;
  64 import static java.time.DayOfWeek.WEDNESDAY;
  65 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  66 import static org.testng.Assert.assertEquals;
  67 import static org.testng.Assert.assertSame;
  68 
  69 import java.util.ArrayList;
  70 import java.util.Arrays;
  71 import java.util.List;
  72 import java.util.Locale;
  73 
  74 import java.time.DateTimeException;
  75 import java.time.DayOfWeek;
  76 import java.time.LocalDate;
  77 import java.time.LocalTime;
  78 import java.time.Month;
  79 import java.time.format.TextStyle;
  80 import java.time.temporal.ChronoField;
  81 import java.time.temporal.ChronoUnit;
  82 import java.time.temporal.ISOChrono;
  83 import java.time.temporal.JulianFields;
  84 import java.time.temporal.Queries;
  85 import java.time.temporal.Temporal;
  86 import java.time.temporal.TemporalAccessor;
  87 import java.time.temporal.TemporalField;





  88 
  89 import org.testng.annotations.BeforeMethod;
  90 import org.testng.annotations.DataProvider;
  91 import org.testng.annotations.Test;
  92 
  93 /**
  94  * Test DayOfWeek.
  95  */
  96 @Test
  97 public class TCKDayOfWeek extends AbstractDateTimeTest {
  98 
  99     @BeforeMethod
 100     public void setUp() {
 101     }
 102 
 103     //-----------------------------------------------------------------------
 104     @Override
 105     protected List<TemporalAccessor> samples() {
 106         TemporalAccessor[] array = {MONDAY, WEDNESDAY, SUNDAY, };
 107         return Arrays.asList(array);


 160     public void test_factory_CalendricalObject_null() {
 161         DayOfWeek.from((TemporalAccessor) null);
 162     }
 163 
 164     //-----------------------------------------------------------------------
 165     // get(TemporalField)
 166     //-----------------------------------------------------------------------
 167     @Test
 168     public void test_get_TemporalField() {
 169         assertEquals(DayOfWeek.WEDNESDAY.getLong(ChronoField.DAY_OF_WEEK), 3);
 170     }
 171 
 172     @Test
 173     public void test_getLong_TemporalField() {
 174         assertEquals(DayOfWeek.WEDNESDAY.getLong(ChronoField.DAY_OF_WEEK), 3);
 175     }
 176 
 177     //-----------------------------------------------------------------------
 178     // query(TemporalQuery)
 179     //-----------------------------------------------------------------------
 180     @Test
 181     public void test_query_chrono() {
 182         assertEquals(DayOfWeek.FRIDAY.query(Queries.chrono()), null);
 183         assertEquals(Queries.chrono().queryFrom(DayOfWeek.FRIDAY), null);
 184     }
 185 
 186     @Test
 187     public void test_query_zoneId() {
 188         assertEquals(DayOfWeek.FRIDAY.query(Queries.zoneId()), null);
 189         assertEquals(Queries.zoneId().queryFrom(DayOfWeek.FRIDAY), null);
 190     }
 191 
 192     @Test
 193     public void test_query_precision() {
 194         assertEquals(DayOfWeek.FRIDAY.query(Queries.precision()), ChronoUnit.DAYS);
 195         assertEquals(Queries.precision().queryFrom(DayOfWeek.FRIDAY), ChronoUnit.DAYS);
 196     }
 197 
 198     @Test
 199     public void test_query_offset() {
 200         assertEquals(DayOfWeek.FRIDAY.query(Queries.offset()), null);
 201         assertEquals(Queries.offset().queryFrom(DayOfWeek.FRIDAY), null);
 202     }
 203 
 204     @Test
 205     public void test_query_zone() {
 206         assertEquals(DayOfWeek.FRIDAY.query(Queries.zone()), null);
 207         assertEquals(Queries.zone().queryFrom(DayOfWeek.FRIDAY), null);
 208     }
 209 
 210     @Test(expectedExceptions=NullPointerException.class)
 211     public void test_query_null() {
 212         DayOfWeek.FRIDAY.query(null);
 213     }
 214 
 215     //-----------------------------------------------------------------------
 216     // getText()
 217     //-----------------------------------------------------------------------
 218     @Test(groups={"tck"})
 219     public void test_getText() {
 220         assertEquals(DayOfWeek.MONDAY.getText(TextStyle.SHORT, Locale.US), "Mon");
 221     }
 222 
 223     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
 224     public void test_getText_nullStyle() {
 225         DayOfWeek.MONDAY.getText(null, Locale.US);
 226     }
 227 
 228     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
 229     public void test_getText_nullLocale() {
 230         DayOfWeek.MONDAY.getText(TextStyle.FULL, null);
 231     }
 232 
 233     //-----------------------------------------------------------------------
 234     // plus(long), plus(long,unit)
 235     //-----------------------------------------------------------------------
 236     @DataProvider(name="plus")
 237     Object[][] data_plus() {
 238         return new Object[][] {
 239             {1, -8, 7},
 240             {1, -7, 1},
 241             {1, -6, 2},
 242             {1, -5, 3},
 243             {1, -4, 4},
 244             {1, -3, 5},
 245             {1, -2, 6},
 246             {1, -1, 7},
 247             {1, 0, 1},
 248             {1, 1, 2},
 249             {1, 2, 3},
 250             {1, 3, 4},




  49  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  50  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  51  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  52  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  53  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  54  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  55  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  56  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  57  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  58  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  59  */
  60 package tck.java.time;
  61 
  62 import static java.time.DayOfWeek.MONDAY;
  63 import static java.time.DayOfWeek.SUNDAY;
  64 import static java.time.DayOfWeek.WEDNESDAY;
  65 import static java.time.temporal.ChronoField.DAY_OF_WEEK;
  66 import static org.testng.Assert.assertEquals;
  67 import static org.testng.Assert.assertSame;
  68 





  69 import java.time.DateTimeException;
  70 import java.time.DayOfWeek;
  71 import java.time.LocalDate;
  72 import java.time.LocalTime;
  73 import java.time.chrono.IsoChronology;
  74 import java.time.format.TextStyle;
  75 import java.time.temporal.ChronoField;
  76 import java.time.temporal.ChronoUnit;

  77 import java.time.temporal.JulianFields;
  78 import java.time.temporal.Queries;
  79 import java.time.temporal.Temporal;
  80 import java.time.temporal.TemporalAccessor;
  81 import java.time.temporal.TemporalField;
  82 import java.time.temporal.TemporalQuery;
  83 import java.util.ArrayList;
  84 import java.util.Arrays;
  85 import java.util.List;
  86 import java.util.Locale;
  87 
  88 import org.testng.annotations.BeforeMethod;
  89 import org.testng.annotations.DataProvider;
  90 import org.testng.annotations.Test;
  91 
  92 /**
  93  * Test DayOfWeek.
  94  */
  95 @Test
  96 public class TCKDayOfWeek extends AbstractDateTimeTest {
  97 
  98     @BeforeMethod
  99     public void setUp() {
 100     }
 101 
 102     //-----------------------------------------------------------------------
 103     @Override
 104     protected List<TemporalAccessor> samples() {
 105         TemporalAccessor[] array = {MONDAY, WEDNESDAY, SUNDAY, };
 106         return Arrays.asList(array);


 159     public void test_factory_CalendricalObject_null() {
 160         DayOfWeek.from((TemporalAccessor) null);
 161     }
 162 
 163     //-----------------------------------------------------------------------
 164     // get(TemporalField)
 165     //-----------------------------------------------------------------------
 166     @Test
 167     public void test_get_TemporalField() {
 168         assertEquals(DayOfWeek.WEDNESDAY.getLong(ChronoField.DAY_OF_WEEK), 3);
 169     }
 170 
 171     @Test
 172     public void test_getLong_TemporalField() {
 173         assertEquals(DayOfWeek.WEDNESDAY.getLong(ChronoField.DAY_OF_WEEK), 3);
 174     }
 175 
 176     //-----------------------------------------------------------------------
 177     // query(TemporalQuery)
 178     //-----------------------------------------------------------------------
 179     @DataProvider(name="query")
 180     Object[][] data_query() {
 181         return new Object[][] {
 182                 {DayOfWeek.FRIDAY, Queries.chronology(), null},
 183                 {DayOfWeek.FRIDAY, Queries.zoneId(), null},
 184                 {DayOfWeek.FRIDAY, Queries.precision(), ChronoUnit.DAYS},
 185                 {DayOfWeek.FRIDAY, Queries.zone(), null},
 186                 {DayOfWeek.FRIDAY, Queries.offset(), null},
 187                 {DayOfWeek.FRIDAY, Queries.localDate(), null},
 188                 {DayOfWeek.FRIDAY, Queries.localTime(), null},
 189         };





 190     }
 191 
 192     @Test(dataProvider="query")
 193     public <T> void test_query(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 194         assertEquals(temporal.query(query), expected);

 195     }
 196 
 197     @Test(dataProvider="query")
 198     public <T> void test_queryFrom(TemporalAccessor temporal, TemporalQuery<T> query, T expected) {
 199         assertEquals(query.queryFrom(temporal), expected);

 200     }
 201 
 202     @Test(expectedExceptions=NullPointerException.class)
 203     public void test_query_null() {
 204         DayOfWeek.FRIDAY.query(null);
 205     }
 206 
 207     //-----------------------------------------------------------------------
 208     // getText()
 209     //-----------------------------------------------------------------------
 210     @Test(groups={"tck"})
 211     public void test_getText() {
 212         assertEquals(DayOfWeek.MONDAY.getDisplayName(TextStyle.SHORT, Locale.US), "Mon");
 213     }
 214 
 215     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
 216     public void test_getText_nullStyle() {
 217         DayOfWeek.MONDAY.getDisplayName(null, Locale.US);
 218     }
 219 
 220     @Test(expectedExceptions = NullPointerException.class, groups={"tck"})
 221     public void test_getText_nullLocale() {
 222         DayOfWeek.MONDAY.getDisplayName(TextStyle.FULL, null);
 223     }
 224 
 225     //-----------------------------------------------------------------------
 226     // plus(long), plus(long,unit)
 227     //-----------------------------------------------------------------------
 228     @DataProvider(name="plus")
 229     Object[][] data_plus() {
 230         return new Object[][] {
 231             {1, -8, 7},
 232             {1, -7, 1},
 233             {1, -6, 2},
 234             {1, -5, 3},
 235             {1, -4, 4},
 236             {1, -3, 5},
 237             {1, -2, 6},
 238             {1, -1, 7},
 239             {1, 0, 1},
 240             {1, 1, 2},
 241             {1, 2, 3},
 242             {1, 3, 4},