Search in sources :

Example 1 with ZoneRulesException

use of java.time.zone.ZoneRulesException in project jdk8u_jdk by JetBrains.

the class TCKZoneIdSerialization method test_deserialization_lenient_characters.

@Test
public void test_deserialization_lenient_characters() throws Exception {
    // an ID can be loaded without validation during deserialization
    String id = "QWERTYUIOPASDFGHJKLZXCVBNM~/._+-";
    ZoneId deser = deserialize(id);
    // getId, equals, hashCode, toString and normalized are OK
    assertEquals(deser.getId(), id);
    assertEquals(deser.toString(), id);
    assertEquals(deser, deser);
    assertEquals(deser.hashCode(), deser.hashCode());
    assertEquals(deser.normalized(), deser);
    // getting the rules is not
    try {
        deser.getRules();
        fail();
    } catch (ZoneRulesException ex) {
    // expected
    }
}
Also used : ZoneRulesException(java.time.zone.ZoneRulesException) ZoneId(java.time.ZoneId) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 2 with ZoneRulesException

use of java.time.zone.ZoneRulesException in project jdk8u_jdk by JetBrains.

the class ZoneRegion method ofId.

/**
     * Obtains an instance of {@code ZoneId} from an identifier.
     *
     * @param zoneId  the time-zone ID, not null
     * @param checkAvailable  whether to check if the zone ID is available
     * @return the zone ID, not null
     * @throws DateTimeException if the ID format is invalid
     * @throws ZoneRulesException if checking availability and the ID cannot be found
     */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
    Objects.requireNonNull(zoneId, "zoneId");
    checkName(zoneId);
    ZoneRules rules = null;
    try {
        // always attempt load for better behavior after deserialization
        rules = ZoneRulesProvider.getRules(zoneId, true);
    } catch (ZoneRulesException ex) {
        if (checkAvailable) {
            throw ex;
        }
    }
    return new ZoneRegion(zoneId, rules);
}
Also used : ZoneRulesException(java.time.zone.ZoneRulesException) ZoneRules(java.time.zone.ZoneRules)

Example 3 with ZoneRulesException

use of java.time.zone.ZoneRulesException in project j2objc by google.

the class ZoneRulesExceptionTest method test_constructor_message.

@Test
public void test_constructor_message() {
    ZoneRulesException ex = new ZoneRulesException("message");
    assertEquals("message", ex.getMessage());
    assertNull(ex.getCause());
}
Also used : ZoneRulesException(java.time.zone.ZoneRulesException) Test(org.junit.Test)

Example 4 with ZoneRulesException

use of java.time.zone.ZoneRulesException in project Bytecoder by mirkosertic.

the class ZoneRegion method ofId.

/**
 * Obtains an instance of {@code ZoneId} from an identifier.
 *
 * @param zoneId  the time-zone ID, not null
 * @param checkAvailable  whether to check if the zone ID is available
 * @return the zone ID, not null
 * @throws DateTimeException if the ID format is invalid
 * @throws ZoneRulesException if checking availability and the ID cannot be found
 */
static ZoneRegion ofId(String zoneId, boolean checkAvailable) {
    Objects.requireNonNull(zoneId, "zoneId");
    checkName(zoneId);
    ZoneRules rules = null;
    try {
        // always attempt load for better behavior after deserialization
        rules = ZoneRulesProvider.getRules(zoneId, true);
    } catch (ZoneRulesException ex) {
        if (checkAvailable) {
            throw ex;
        }
    }
    return new ZoneRegion(zoneId, rules);
}
Also used : ZoneRulesException(java.time.zone.ZoneRulesException) ZoneRules(java.time.zone.ZoneRules)

Example 5 with ZoneRulesException

use of java.time.zone.ZoneRulesException in project j2objc by google.

the class ZoneRulesExceptionTest method test_constructor_message_cause.

@Test
public void test_constructor_message_cause() {
    Throwable cause = new Exception();
    ZoneRulesException ex = new ZoneRulesException("message", cause);
    assertEquals("message", ex.getMessage());
    assertSame(cause, ex.getCause());
}
Also used : ZoneRulesException(java.time.zone.ZoneRulesException) ZoneRulesException(java.time.zone.ZoneRulesException) Test(org.junit.Test)

Aggregations

ZoneRulesException (java.time.zone.ZoneRulesException)10 ZoneId (java.time.ZoneId)4 ZoneRules (java.time.zone.ZoneRules)4 Test (org.junit.Test)3 AbstractTCKTest (tck.java.time.AbstractTCKTest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 StreamCorruptedException (java.io.StreamCorruptedException)1 LocalDateTime (java.time.LocalDateTime)1 ZoneOffset (java.time.ZoneOffset)1 Date (java.util.Date)1 TimeZone (java.util.TimeZone)1 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)1 InvalidArgumentException (org.neo4j.exceptions.InvalidArgumentException)1 TemporalParseException (org.neo4j.exceptions.TemporalParseException)1 Test (org.testng.annotations.Test)1