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

com.fitbur.assertj.api.WithAssertions Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
/**
 * Licensed 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.
 *
 * Copyright 2012-2016 the original author or authors.
 */
package com.fitbur.assertj.api;

import java.io.File;
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

import com.fitbur.assertj.api.ThrowableAssert.ThrowingCallable;
import com.fitbur.assertj.api.filter.Filters;
import com.fitbur.assertj.condition.DoesNotHave;
import com.fitbur.assertj.condition.Not;
import com.fitbur.assertj.data.Index;
import com.fitbur.assertj.data.MapEntry;
import com.fitbur.assertj.data.Offset;
import com.fitbur.assertj.groups.Properties;
import com.fitbur.assertj.groups.Tuple;

/**
 *
 * A unified entry point to all non-deprecated assertions from both the new Java 8 core API and the pre-Java 8 core API.
 *
 * As a convenience, the methods are defined in an interface so that no static imports are necessary if the test class
 * implements this interface.
 *
 * Based on an idea by David Gageot :
 *
 * http://blog.javabien.net/2014/04/23/what-if-assertj-used-java-8/
 *
 * @author Alan Rothkopf
 *
 */
public interface WithAssertions {

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#offset(Float)}
   */
  default public Offset offset(final Float value) {
    return Assertions.offset(value);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#offset(Double)}
   */
  default public Offset offset(final Double value) {
    return Assertions.offset(value);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#entry(Object, Object)}
   */
  default public  MapEntry entry(final K key, final V value) {
    return Assertions.entry(key, value);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#fail(String)}
   */
  default public void fail(final String failureMessage) {
    Assertions.fail(failureMessage);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#fail(String,Throwable)}
   */
  default public void fail(final String failureMessage, final Throwable realCause) {
    Assertions.fail(failureMessage, realCause);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#not(Condition)}
   */
  default public  Not not(final Condition condition) {
    return Assertions.not(condition);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#allOf(Iterable)}
   */
  default public  Condition allOf(final Iterable> conditions) {
    return Assertions.allOf(conditions);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#allOf(Condition[])}
   */
  default public  Condition allOf(@SuppressWarnings("unchecked") final Condition... conditions) {
    return Assertions.allOf(conditions);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(T[])}
   */
  default public  AbstractObjectArrayAssert assertThat(final T[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(AssertDelegateTarget)}
   */
  default public  T assertThat(final T assertion) {
    return Assertions.assertThat(assertion);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Map)}
   */
  default public  AbstractMapAssert, K, V> assertThat(final Map actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(short)}
   */
  default public AbstractShortAssert assertThat(final short actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(long)}
   */
  default public AbstractLongAssert assertThat(final long actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Long)}
   */
  default public AbstractLongAssert assertThat(final Long actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(long[])}
   */
  default public AbstractLongArrayAssert assertThat(final long[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(T)}
   */
  default public  AbstractObjectAssert assertThat(final T actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(String)}
   */
  default public AbstractCharSequenceAssert assertThat(final String actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Date)}
   */
  default public AbstractDateAssert assertThat(final Date actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Throwable)}
   */
  default public AbstractThrowableAssert assertThat(final Throwable actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(BigDecimal)}
   */
  default public AbstractBigDecimalAssert assertThat(final BigDecimal actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(CharSequence)}
   */
  default public AbstractCharSequenceAssert assertThat(final CharSequence actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(short[])}
   */
  default public AbstractShortArrayAssert assertThat(final short[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Short)}
   */
  default public AbstractShortAssert assertThat(final Short actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Class)}
   */
  default public AbstractClassAssert assertThat(final Class actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Character)}
   */
  default public AbstractCharacterAssert assertThat(final Character actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(char[])}
   */
  default public AbstractCharArrayAssert assertThat(final char[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(char)}
   */
  default public AbstractCharacterAssert assertThat(final char actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Comparable)}
   */
  default public > AbstractComparableAssert assertThat(final T actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Iterable)}
   */
  @SuppressWarnings("unchecked")
  default public  AbstractIterableAssert, T> assertThat(final Iterable actual) {
    return (AbstractIterableAssert, T>) Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Iterator)}
   */
  @SuppressWarnings("unchecked")
  default public  AbstractIterableAssert, T> assertThat(final Iterator actual) {
    return (AbstractIterableAssert, T>) Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Boolean)}
   */
  default public AbstractBooleanAssert assertThat(final Boolean actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(boolean)}
   */
  default public AbstractBooleanArrayAssert assertThat(final boolean[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(byte)}
   */
  default public AbstractByteAssert assertThat(final byte actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Byte)}
   */
  default public AbstractByteAssert assertThat(final Byte actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(byte[])}
   */
  default public AbstractByteArrayAssert assertThat(final byte[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(boolean)}
   */
  default public AbstractBooleanAssert assertThat(final boolean actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(float)}
   */
  default public AbstractFloatAssert assertThat(final float actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(InputStream)}
   */
  default public AbstractInputStreamAssert assertThat(final InputStream actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(File)}
   */
  default public AbstractFileAssert assertThat(final File actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(int[])}
   */
  default public AbstractIntArrayAssert assertThat(final int[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Float)}
   */
  default public AbstractFloatAssert assertThat(final Float actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(int)}
   */
  default public AbstractIntegerAssert assertThat(final int actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(float[])}
   */
  default public AbstractFloatArrayAssert assertThat(final float[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Integer)}
   */
  default public AbstractIntegerAssert assertThat(final Integer actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(double)}
   */
  default public AbstractDoubleAssert assertThat(final double actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Double)}
   */
  default public AbstractDoubleAssert assertThat(final Double actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(List)}
   */
  @SuppressWarnings("unchecked")
  default public  AbstractListAssert, T> assertThat(final List actual) {
    return (AbstractListAssert, T>) Assertions.assertThat(actual);
  } 

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(List)}
   */
  @SuppressWarnings("unchecked")
  default public  AbstractListAssert, T> assertThat(final Stream actual) {
    return (AbstractListAssert, T>) Assertions.assertThat(actual);
  }
  
  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(double[])}
   */
  default public AbstractDoubleArrayAssert assertThat(final double[] actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#extractProperty(String)}
   */
  default public Properties extractProperty(final String propertyName) {
    return Assertions.extractProperty(propertyName);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#extractProperty(String,Class)}
   */
  default public  Properties extractProperty(final String propertyName, final Class propertyType) {
    return Assertions.extractProperty(propertyName, propertyType);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#tuple(Object[])}
   */
  default public Tuple tuple(final Object... values) {
    return Assertions.tuple(values);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#atIndex(int)}
   */
  default public Index atIndex(final int actual) {
    return Assertions.atIndex(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#within(Double)}
   */
  default public Offset within(final Double actual) {
    return Assertions.within(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#within(BigDecimal)}
   */
  default public Offset within(final BigDecimal actual) {
    return Assertions.within(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#within(Float)}
   */
  default public Offset within(final Float actual) {
    return Assertions.within(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#anyOf(Iterable)}
   */
  default public  Condition anyOf(final Iterable> conditions) {
    return Assertions.anyOf(conditions);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#anyOf(Condition[])}
   */
  default public  Condition anyOf(@SuppressWarnings("unchecked") final Condition... conditions) {
    return Assertions.anyOf(conditions);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#doesNotHave(Condition)}
   */
  default public  DoesNotHave doesNotHave(final Condition condition) {
    return Assertions.doesNotHave(condition);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#contentOf(File,String)}
   */
  default public String contentOf(final File file, final String charsetName) {
    return Assertions.contentOf(file, charsetName);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#contentOf(File)}
   */
  default public String contentOf(final File actual) {
    return Assertions.contentOf(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#contentOf(File,Charset)}
   */
  default public String contentOf(final File file, final Charset charset) {
    return Assertions.contentOf(file, charset);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#linesOf(File)}
   */
  default public List linesOf(final File actual) {
    return Assertions.linesOf(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#linesOf(File,String)}
   */
  default public List linesOf(final File file, final String charsetName) {
    return Assertions.linesOf(file, charsetName);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#linesOf(File,Charset)}
   */
  default public List linesOf(final File actual, final Charset arg1) {
    return Assertions.linesOf(actual, arg1);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#setRemoveAssertJRelatedElementsFromStackTrace}
   */
  default public void setRemoveAssertJRelatedElementsFromStackTrace(final boolean actual) {
    Assertions.setRemoveAssertJRelatedElementsFromStackTrace(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#failBecauseExceptionWasNotThrown}
   */
  default public void failBecauseExceptionWasNotThrown(final Class exceptionClass) {
    Assertions.failBecauseExceptionWasNotThrown(exceptionClass);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#setAllowExtractingPrivateFields}
   */
  default public void setAllowExtractingPrivateFields(final boolean actual) {
    Assertions.setAllowExtractingPrivateFields(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#registerCustomDateFormat(DateFormat)}
   */
  default public void registerCustomDateFormat(final DateFormat actual) {
    Assertions.registerCustomDateFormat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#registerCustomDateFormat(String)}
   */
  default public void registerCustomDateFormat(final String actual) {
    Assertions.registerCustomDateFormat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#useDefaultDateFormatsOnly}
   */
  default public void useDefaultDateFormatsOnly() {
    Assertions.useDefaultDateFormatsOnly();
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(ZonedDateTime)}
   */
  default public AbstractZonedDateTimeAssert assertThat(final ZonedDateTime actual) {
    return Assertions.assertThat(actual);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(CompletableFuture)}
   */
  default public  CompletableFutureAssert assertThat(final CompletableFuture future) {
    return Assertions.assertThat(future);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(Optional)}
   */
  default public  OptionalAssert assertThat(final Optional optional) {
    return Assertions.assertThat(optional);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(java.util.OptionalDouble)}
   */
  default public OptionalDoubleAssert assertThat(final OptionalDouble optional) {
    return Assertions.assertThat(optional);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(java.util.OptionalInt)}
   */
  default public OptionalIntAssert assertThat(final OptionalInt optional) {
    return Assertions.assertThat(optional);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(java.util.OptionalLong)}
   */
  default public OptionalLongAssert assertThat(final OptionalLong optional) {
    return Assertions.assertThat(optional);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(LocalDateTime)}
   */
  default public AbstractLocalDateTimeAssert assertThat(final LocalDateTime localDateTime) {
    return Assertions.assertThat(localDateTime);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(LocalDate)}
   */
  default public AbstractLocalDateAssert assertThat(final LocalDate localDate) {
    return Assertions.assertThat(localDate);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(LocalTime)}
   */
  default public AbstractLocalTimeAssert assertThat(final LocalTime localTime) {
    return Assertions.assertThat(localTime);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(OffsetTime)}
   */
  default public AbstractOffsetTimeAssert assertThat(final OffsetTime offsetTime) {
    return Assertions.assertThat(offsetTime);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThat(OffsetDateTime)}
   */
  default public AbstractOffsetDateTimeAssert assertThat(final OffsetDateTime offsetDateTime) {
    return Assertions.assertThat(offsetDateTime);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#assertThatThrownBy(ThrowingCallable)}
   */
  default public AbstractThrowableAssert assertThatThrownBy(final ThrowingCallable shouldRaiseThrowable) {
    return Assertions.assertThatThrownBy(shouldRaiseThrowable);
  }

  /**
   * Delegate call to {@link com.fitbur.assertj.api.Assertions#catchThrowable(ThrowingCallable)}
   */
  default public Throwable catchThrowable(final ThrowingCallable shouldRaiseThrowable) {
    return Assertions.catchThrowable(shouldRaiseThrowable);
  }
  
  /**
   * Entry point to check that an exception of type T is thrown by a given {@code throwingCallable}  
   * which allows to chain assertions on the thrown exception.
   * 

* Example: *

 assertThatExceptionOfType(IOException.class).isThrownBy(() -> { throw new IOException("boom!"); })
   *                                       .withMessage("boom!"); 
* * This method is more or less the same of {@link #assertThatThrownBy(ThrowingCallable)} but in a more natural way. * @param actual the actual value. * @return the created {@link ThrowableTypeAssert}. */ default public ThrowableTypeAssert assertThatExceptionOfType(final Class exceptionType) { return Assertions.assertThatExceptionOfType(exceptionType); } // -------------------------------------------------------------------------------------------------- // Filter methods : not assertions but here to have a complete entry point to all AssertJ features. // -------------------------------------------------------------------------------------------------- /** * Delegate call to {@link com.fitbur.assertj.api.Assertions#filter(E[])} */ default public Filters filter(final E[] array) { return Assertions.filter(array); } /** * Delegate call to {@link com.fitbur.assertj.api.Assertions#filter(Iterable)} */ default public Filters filter(final Iterable iterableToFilter) { return Assertions.filter(iterableToFilter); } }