All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.juneau.assertions.FluentZonedDateTimeAssertion Maven / Gradle / Ivy

The newest version!
// ***************************************************************************************************************************
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file *
// * distributed with this work for additional information regarding copyright ownership.  The ASF licenses this file        *
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance            *
// * with the License.  You may obtain a copy of the License at                                                              *
// *                                                                                                                         *
// *  http://www.apache.org/licenses/LICENSE-2.0                                                                             *
// *                                                                                                                         *
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an  *
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the License for the        *
// * specific language governing permissions and limitations under the License.                                              *
// ***************************************************************************************************************************
package org.apache.juneau.assertions;

import static org.apache.juneau.common.internal.ArgUtils.*;

import java.io.*;
import java.time.*;
import java.time.temporal.*;
import java.util.function.*;

import org.apache.juneau.cp.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.serializer.*;

/**
 * Used for fluent assertion calls against {@link ZonedDateTime} objects.
 *
 * 
Example:
*

* // Validates the response expiration is after the current date. * client * .get(URL) * .run() * .getHeader("Expires").asDateHeader().assertZonedDateTime().isAfterNow(); *

* * *
Test Methods:
*

*

    *
  • {@link FluentZonedDateTimeAssertion} *
      *
    • {@link FluentZonedDateTimeAssertion#is(ZonedDateTime,ChronoUnit) is(ZonedDateTime,ChronoUnit)} *
    • {@link FluentZonedDateTimeAssertion#isAfter(ZonedDateTime) isAfter(ZonedDateTime)} *
    • {@link FluentZonedDateTimeAssertion#isAfterNow() isAfterNow()} *
    • {@link FluentZonedDateTimeAssertion#isBefore(ZonedDateTime) isBefore(ZonedDateTime)} *
    • {@link FluentZonedDateTimeAssertion#isBeforeNow() isBeforeNow()} *
    • {@link FluentZonedDateTimeAssertion#isBetween(ZonedDateTime,ZonedDateTime) isBetween(ZonedDateTime,ZonedDateTime)} *
    *
  • {@link FluentComparableAssertion} *
      *
    • {@link FluentComparableAssertion#isGt(Comparable) isGt(Comparable)} *
    • {@link FluentComparableAssertion#isGte(Comparable) isGte(Comparable)} *
    • {@link FluentComparableAssertion#isLt(Comparable) isLt(Comparable)} *
    • {@link FluentComparableAssertion#isLte(Comparable) isLte(Comparable)} *
    • {@link FluentComparableAssertion#isBetween(Comparable,Comparable) isBetween(Comparable,Comparable)} *
    *
  • {@link FluentObjectAssertion} *
      *
    • {@link FluentObjectAssertion#isExists() isExists()} *
    • {@link FluentObjectAssertion#is(Object) is(Object)} *
    • {@link FluentObjectAssertion#is(Predicate) is(Predicate)} *
    • {@link FluentObjectAssertion#isNot(Object) isNot(Object)} *
    • {@link FluentObjectAssertion#isAny(Object...) isAny(Object...)} *
    • {@link FluentObjectAssertion#isNotAny(Object...) isNotAny(Object...)} *
    • {@link FluentObjectAssertion#isNull() isNull()} *
    • {@link FluentObjectAssertion#isNotNull() isNotNull()} *
    • {@link FluentObjectAssertion#isString(String) isString(String)} *
    • {@link FluentObjectAssertion#isJson(String) isJson(String)} *
    • {@link FluentObjectAssertion#isSame(Object) isSame(Object)} *
    • {@link FluentObjectAssertion#isSameJsonAs(Object) isSameJsonAs(Object)} *
    • {@link FluentObjectAssertion#isSameSortedJsonAs(Object) isSameSortedJsonAs(Object)} *
    • {@link FluentObjectAssertion#isSameSerializedAs(Object, WriterSerializer) isSameSerializedAs(Object, WriterSerializer)} *
    • {@link FluentObjectAssertion#isType(Class) isType(Class)} *
    • {@link FluentObjectAssertion#isExactType(Class) isExactType(Class)} *
    *
* *
Transform Methods:
*

*

    *
  • {@link FluentObjectAssertion} *
      *
    • {@link FluentObjectAssertion#asString() asString()} *
    • {@link FluentObjectAssertion#asString(WriterSerializer) asString(WriterSerializer)} *
    • {@link FluentObjectAssertion#asString(Function) asString(Function)} *
    • {@link FluentObjectAssertion#asJson() asJson()} *
    • {@link FluentObjectAssertion#asJsonSorted() asJsonSorted()} *
    • {@link FluentObjectAssertion#asTransformed(Function) asApplied(Function)} *
    • {@link FluentObjectAssertion#asAny() asAny()} *
    *
* *
Configuration Methods:
*

*

    *
  • {@link Assertion} *
      *
    • {@link Assertion#setMsg(String, Object...) setMsg(String, Object...)} *
    • {@link Assertion#setOut(PrintStream) setOut(PrintStream)} *
    • {@link Assertion#setSilent() setSilent()} *
    • {@link Assertion#setStdOut() setStdOut()} *
    • {@link Assertion#setThrowable(Class) setThrowable(Class)} *
    *
* *
See Also:
* * @param The return type. */ @FluentSetters(returns="FluentZonedDateTimeAssertion") public class FluentZonedDateTimeAssertion extends FluentComparableAssertion { //----------------------------------------------------------------------------------------------------------------- // Static //----------------------------------------------------------------------------------------------------------------- private static final Messages MESSAGES = Messages.of(FluentZonedDateTimeAssertion.class, "Messages"); private static final String MSG_unexpectedValue = MESSAGES.getString("unexpectedValue"), MSG_valueWasNotAfterExpected = MESSAGES.getString("valueWasNotAfterExpected"), MSG_valueWasNotBeforeExpected = MESSAGES.getString("valueWasNotBeforeExpected"); //----------------------------------------------------------------------------------------------------------------- // Instance //----------------------------------------------------------------------------------------------------------------- /** * Constructor. * * @param value * The object being tested. *
Can be null. * @param returns * The object to return after a test method is called. *
If null, the test method returns this object allowing multiple test method calls to be * used on the same assertion. */ public FluentZonedDateTimeAssertion(ZonedDateTime value, R returns) { this(null, value, returns); } /** * Chained constructor. * *

* Used when transforming one assertion into another so that the assertion config can be used by the new assertion. * * @param creator * The assertion that created this assertion. *
Should be null if this is the top-level assertion. * @param value * The object being tested. *
Can be null. * @param returns * The object to return after a test method is called. *
If null, the test method returns this object allowing multiple test method calls to be * used on the same assertion. */ public FluentZonedDateTimeAssertion(Assertion creator, ZonedDateTime value, R returns) { super(creator, value, returns); } //----------------------------------------------------------------------------------------------------------------- // Test methods //----------------------------------------------------------------------------------------------------------------- /** * Asserts that the value equals the specified value at the specified precision. * * @param value The value to check against. * @param precision The precision (e.g. {@link ChronoUnit#SECONDS}. * @return The fluent return object. * @throws AssertionError If assertion failed. */ public R is(ZonedDateTime value, ChronoUnit precision) throws AssertionError { assertArgNotNull("precision", precision); ZonedDateTime v = orElse(null); if (valueIsNull() && value == null) return returns(); if (valueIsNotNull() && value != null) { Duration d = Duration.between(value(), value); if (d.compareTo(precision.getDuration()) <= 0) return returns(); } throw error(MSG_unexpectedValue, value, v); } /** * Asserts that the value is after the specified value. * * @param value The values to check against. * @return The fluent return object. * @throws AssertionError If assertion failed. */ public R isAfter(ZonedDateTime value) throws AssertionError { assertArgNotNull("value", value); if (! (value().isAfter(value))) throw error(MSG_valueWasNotAfterExpected, value, value()); return returns(); } /** * Asserts that the value is after the current date. * * @return The fluent return object. * @throws AssertionError If assertion failed. */ public R isAfterNow() throws AssertionError { return isAfter(ZonedDateTime.now()); } /** * Asserts that the value is before the specified value. * * @param value The values to check against. * @return The fluent return object. * @throws AssertionError If assertion failed. */ public R isBefore(ZonedDateTime value) throws AssertionError { assertArgNotNull("value", value); if (! (value().isBefore(value))) throw error(MSG_valueWasNotBeforeExpected, value, value()); return returns(); } /** * Asserts that the value is before the current date. * * @return The fluent return object. * @throws AssertionError If assertion failed. */ public R isBeforeNow() throws AssertionError { return isBefore(ZonedDateTime.now()); } /** * Asserts that the value is between (inclusive) the specified upper and lower values. * * @param lower The lower value to check against. * @param upper The upper value to check against. * @return The fluent return object. * @throws AssertionError If assertion failed. */ public R isBetween(ZonedDateTime lower, ZonedDateTime upper) throws AssertionError { isExists(); assertArgNotNull("lower", lower); assertArgNotNull("upper", upper); isLte(upper); isGte(lower); return returns(); } //----------------------------------------------------------------------------------------------------------------- // Fluent setters //----------------------------------------------------------------------------------------------------------------- // @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ public FluentZonedDateTimeAssertion setMsg(String msg, Object...args) { super.setMsg(msg, args); return this; } @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ public FluentZonedDateTimeAssertion setOut(PrintStream value) { super.setOut(value); return this; } @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ public FluentZonedDateTimeAssertion setSilent() { super.setSilent(); return this; } @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ public FluentZonedDateTimeAssertion setStdOut() { super.setStdOut(); return this; } @Override /* GENERATED - org.apache.juneau.assertions.Assertion */ public FluentZonedDateTimeAssertion setThrowable(Class value) { super.setThrowable(value); return this; } // }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy