![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.juneau.assertions.FluentAssertion Maven / Gradle / Ivy
Show all versions of juneau-assertions Show documentation
// ***************************************************************************************************************************
// * 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 java.io.*;
import org.apache.juneau.internal.*;
/**
* Parent class of all fluent assertion calls.
*
*
* Defines a {@link #returns()} method that returns an original object.
* Assertion test methods that pass use this method to return to the origin of the call.
*
*
Example:
*
* // Create a basic REST client with JSON support and download a bean.
* MyPojo myPojo = ...;
* MyTestedBean myTestedBean = ...;
*
* Assertion assertion = new FluentBeanAssertion<MyPojo,MyTestedBean>(myPojo , myTestedBean );
* myPojo = assertion .test(x -> x .getMyProperty().equals("foo" )); // Returns myPojo after test.
*
*
* For subclasses such as {@link IntegerAssertion}, the return object is simply itself so that multiple tests
* can be performed using the same assertion.
*
Example:
*
* public class IntegerAssertion extends FluentIntegerAssertion<IntegerAssertion> {
* ...
* }
*
* Assertion assertion = new IntegerAssertion(123);
* assertion
* .isNotNull()
* .isGt(100)
* ;
*
*
*
* Test Methods:
*
*
* - None
*
*
* Transform Methods:
*
*
* - None
*
*
* 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="FluentAssertion")
public abstract class FluentAssertion extends Assertion {
//-----------------------------------------------------------------------------------------------------------------
// Instance
//-----------------------------------------------------------------------------------------------------------------
private final R returns;
/**
* Constructor.
*
* @param creator
* The assertion that created this assertion.
*
Should be null if this is the top-level assertion.
* @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.
*/
protected FluentAssertion(Assertion creator, R returns) {
super(creator);
this.returns = returns;
}
//-----------------------------------------------------------------------------------------------------------------
// Fluent setters
//-----------------------------------------------------------------------------------------------------------------
//
@Override /* GENERATED - org.apache.juneau.assertions.Assertion */
public FluentAssertion setMsg(String msg, Object...args) {
super.setMsg(msg, args);
return this;
}
@Override /* GENERATED - org.apache.juneau.assertions.Assertion */
public FluentAssertion setOut(PrintStream value) {
super.setOut(value);
return this;
}
@Override /* GENERATED - org.apache.juneau.assertions.Assertion */
public FluentAssertion setSilent() {
super.setSilent();
return this;
}
@Override /* GENERATED - org.apache.juneau.assertions.Assertion */
public FluentAssertion setStdOut() {
super.setStdOut();
return this;
}
@Override /* GENERATED - org.apache.juneau.assertions.Assertion */
public FluentAssertion setThrowable(Class extends java.lang.RuntimeException> value) {
super.setThrowable(value);
return this;
}
//
//-----------------------------------------------------------------------------------------------------------------
// Utility methods
//-----------------------------------------------------------------------------------------------------------------
/**
* Returns the object that the fluent methods on this class should return.
*
* @return The response object.
*/
@SuppressWarnings("unchecked")
protected R returns() {
return returns != null ? returns : (R)this;
}
}