org.assertj.guava.api.Assertions Maven / Gradle / Ivy
/*
* 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-2023 the original author or authors.
*/
package org.assertj.guava.api;
import org.assertj.core.data.MapEntry;
import com.google.common.base.Optional;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import com.google.common.collect.Range;
import com.google.common.collect.RangeMap;
import com.google.common.collect.RangeSet;
import com.google.common.collect.Table;
import com.google.common.io.ByteSource;
/**
* The entry point for all Guava assertions.
*
* @author marcelfalliere
* @author miralak
* @author Kornel
* @author Jan Gorman
* @author Joel Costigliola
* @author Marcin Kwaczyński
* @author Max Daniline
* @author Ilya Koshaleu
*/
public class Assertions implements InstanceOfAssertFactories {
public static ByteSourceAssert assertThat(final ByteSource actual) {
return new ByteSourceAssert(actual);
}
public static MultimapAssert assertThat(final Multimap actual) {
return new MultimapAssert<>(actual);
}
public static OptionalAssert assertThat(final Optional actual) {
return new OptionalAssert<>(actual);
}
public static > RangeAssert assertThat(final Range actual) {
return new RangeAssert<>(actual);
}
public static , V> RangeMapAssert assertThat(final RangeMap actual) {
return new RangeMapAssert<>(actual);
}
public static > RangeSetAssert assertThat(final RangeSet actual) {
return new RangeSetAssert<>(actual);
}
public static TableAssert assertThat(Table actual) {
return new TableAssert<>(actual);
}
public static MultisetAssert assertThat(final Multiset actual) {
return new MultisetAssert<>(actual);
}
// ------------------------------------------------------------------------------------------------------
// Data utility methods : not assertions but here to have a single entry point to all AssertJ Guava features.
// ------------------------------------------------------------------------------------------------------
/**
* Only delegate to {@link MapEntry#entry(Object, Object)} so that Assertions offers a fully featured entry point to all
* AssertJ Guava features (but you can use {@link MapEntry} if you prefer).
*
* Typical usage is to call entry
in MultimapAssert contains
assertion as shown below :
*
*
Multimap<String, String> actual = ArrayListMultimap.create();
* actual.putAll("Lakers", newArrayList("Kobe Bryant", "Magic Johnson", "Kareem Abdul Jabbar"));
* actual.putAll("Spurs", newArrayList("Tony Parker", "Tim Duncan", "Manu Ginobili"));
*
* assertThat(actual).contains(entry("Lakers", "Kobe Bryant"), entry("Spurs", "Tim Duncan"));
*
* @param the type of the key of this entry.
* @param the type of the value of this entry.
* @param key the key of the entry to create.
* @param value the value of the entry to create.
*
* @return the built entry
*/
public static MapEntry entry(K key, V value) {
return MapEntry.entry(key, value);
}
/**
* protected to avoid direct instantiation but allowing subclassing.
*/
protected Assertions() {
// empty
}
}