New ImplicitAssertion inspection for implicit isNotNull(), isNotEmpty() and isPresent() assertions that will be covered by chained assertions.

This commit is contained in:
Chris Hodges 2019-06-09 14:04:01 +02:00
parent 178b7d368a
commit 828e61a73b
14 changed files with 810 additions and 12 deletions

View File

@ -279,6 +279,24 @@ You can toggle the various inspections in the Settings/Editor/Inspections in the
```
...and many, many more combinations (more than 150).
- ImplicitAssertion
Detects and removes implicit use of ```isNotNull()```, ```isNotEmpty()``` and
```isPresent()``` when followed by an assertion that will implicitly cover this
check.
```
from: assertThat(string).isNotNull().startsWith("foo");
to: assertThat(string).startsWith("foo");
from: assertThat(list).isNotEmpty().hasSize(10);
to: assertThat(list).hasSize(10);
from: assertThat(optional).isPresent().contains("foo");
to: assertThat(optional).contains("foo");
```
...and many more combinations (more than 100).
- AssertThatJava8Optional
Examines the statement for Java 8 ```Optional``` type and whether the statement
@ -492,6 +510,7 @@ Feel free to use the code (in package ```de.platon42.intellij.jupiter```) for yo
- Added Java 8 Optional ```opt.orElse(null) == null``` case, too.
- Extended JUnitAssertToAssertJ inspection to convert JUnit ```assume```-Statements, too.
- Improved JUnitAssertToAssertJ quick fix to swap expected and actual expressions if the actual one is a constant.
- New ImplicitAssertion inspection for implicit ```isNotNull()```, ```isNotEmpty()``` and ```isPresent()``` assertions that will be covered by chained assertions.
#### V1.0 (06-May-19)
- First release to be considered stable enough for production use.

View File

@ -1,6 +1,6 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.8'
id 'org.jetbrains.intellij' version '0.4.9'
id 'org.jetbrains.kotlin.jvm' version '1.3.31'
id 'jacoco'
id 'com.github.kt3k.coveralls' version '2.8.2'
@ -49,13 +49,7 @@ patchPluginXml {
<li>Added Java 8 Optional opt.orElse(null) == null case, too.
<li>Extended JUnitAssertToAssertJ inspection to convert JUnit assume-Statements, too.
<li>Improved JUnitAssertToAssertJ quick fix to swap expected and actual expressions if the actual one is a constant.
</ul>
<h4>V1.0 (06-May-19)</h4>
<ul>
<li>First release to be considered stable enough for production use.
<li>Fixed a NPE in AssumeThatInsteadOfReturn inspection quickfix for empty else branches.
<li>Fixed missing description for AssumeThatInsteadOfReturn inspection.
<li>Added new AssertThatCollectionOrMapExpression inspection that tries to pull out methods such as isEmpty() or contains() out of an actual assertThat() expression.
<li>New ImplicitAssertion inspection for implicit isNotNull(), isNotEmpty() and isPresent() assertions that will be covered by chained assertions.
</ul>
<p>Full changelog available at <a href="https://github.com/chrisly42/cajon-plugin#changelog">Github project site</a>.</p>
"""

View File

@ -15,6 +15,8 @@ class AssertJClassNames {
@NonNls
const val EXTENSION_POINTS_INTERFACE = "org.assertj.core.api.ExtensionPoints"
@NonNls
const val ENUMERABLE_ASSERT_INTERFACE = "org.assertj.core.api.EnumerableAssert"
@NonNls
const val OBJECT_ENUMERABLE_ASSERT_INTERFACE = "org.assertj.core.api.ObjectEnumerableAssert"
@NonNls
@ -36,7 +38,7 @@ class AssertJClassNames {
@NonNls
const val ABSTRACT_ITERABLE_ASSERT_CLASSNAME = "org.assertj.core.api.AbstractIterableAssert"
@NonNls
const val ABSTRACT_ENUMERABLE_ASSERT_CLASSNAME = "org.assertj.core.api.EnumerableAssert"
const val ABSTRACT_OPTIONAL_ASSERT_CLASSNAME = "org.assertj.core.api.AbstractOptionalAssert"
@NonNls
const val EXTRACTORS_CLASSNAME = "org.assertj.core.extractor.Extractors"
@ -44,5 +46,7 @@ class AssertJClassNames {
const val GUAVA_OPTIONAL_CLASSNAME = "com.google.common.base.Optional"
@NonNls
const val GUAVA_ASSERTIONS_CLASSNAME = "org.assertj.guava.api.Assertions"
@NonNls
const val GUAVA_OPTIONAL_ASSERTIONS_CLASSNAME = "org.assertj.guava.api.OptionalAssert"
}
}

View File

@ -32,6 +32,10 @@ class MethodNames {
const val IS_SAME_AS = "isSameAs"
@NonNls
const val IS_NOT_SAME_AS = "isNotSameAs"
@NonNls
const val HAS_TO_STRING = "hasToString"
@NonNls
const val IS_GREATER_THAN = "isGreaterThan"
@NonNls
@ -61,6 +65,8 @@ class MethodNames {
@NonNls
const val IS_NOT_INSTANCE_OF = "isNotInstanceOf"
@NonNls
const val IS_NULL_OR_EMPTY = "isNullOrEmpty" // terminal, returns void
@NonNls
const val IS_EMPTY = "isEmpty" // terminal, returns void
@NonNls

View File

@ -12,10 +12,10 @@ import com.siyeh.ig.callMatcher.CallMatcher
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_ASSERT_CLASSNAME
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_BOOLEAN_ASSERT_CLASSNAME
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_COMPARABLE_ASSERT_CLASSNAME
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_ENUMERABLE_ASSERT_CLASSNAME
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ABSTRACT_INTEGER_ASSERT_CLASSNAME
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ASSERTIONS_CLASSNAME
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ASSERT_INTERFACE
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.ENUMERABLE_ASSERT_INTERFACE
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.GUAVA_ASSERTIONS_CLASSNAME
import de.platon42.intellij.plugins.cajon.AssertJClassNames.Companion.GUAVA_OPTIONAL_CLASSNAME
import de.platon42.intellij.plugins.cajon.MethodNames
@ -98,7 +98,9 @@ open class AbstractAssertJInspection : AbstractBaseJavaLocalInspectionTool() {
val IS_NOT_NULL = CallMatcher.instanceCall(ASSERT_INTERFACE, MethodNames.IS_NOT_NULL)
.parameterCount(0)!!
val HAS_SIZE = CallMatcher.instanceCall(ABSTRACT_ENUMERABLE_ASSERT_CLASSNAME, MethodNames.HAS_SIZE)
val IS_NOT_EMPTY = CallMatcher.instanceCall(ENUMERABLE_ASSERT_INTERFACE, MethodNames.IS_NOT_EMPTY)
.parameterCount(0)!!
val HAS_SIZE = CallMatcher.instanceCall(ENUMERABLE_ASSERT_INTERFACE, MethodNames.HAS_SIZE)
.parameterTypes("int")!!
val IS_EQUAL_TO_INT = CallMatcher.instanceCall(ABSTRACT_ASSERT_CLASSNAME, MethodNames.IS_EQUAL_TO)

View File

@ -34,6 +34,11 @@ class AssertThatCollectionOrMapExpressionInspection : AbstractAssertJInspection(
Mapping(
CallMatcher.instanceCall(CommonClassNames.JAVA_UTIL_MAP, "containsValue").parameterCount(1),
MethodNames.CONTAINS_VALUE, MethodNames.DOES_NOT_CONTAIN_VALUE
),
// TODO not quite a collection or map expression, maybe move this out to new inspection together with equals and hashcode.
Mapping(
CallMatcher.instanceCall(CommonClassNames.JAVA_LANG_OBJECT, "toString").parameterCount(0),
MethodNames.HAS_TO_STRING, null
)
)
}

View File

@ -0,0 +1,131 @@
package de.platon42.intellij.plugins.cajon.inspections
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.openapi.util.TextRange
import com.intellij.psi.JavaElementVisitor
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiMethodCallExpression
import com.siyeh.ig.callMatcher.CallMatcher
import de.platon42.intellij.plugins.cajon.*
import de.platon42.intellij.plugins.cajon.quickfixes.DeleteMethodCallQuickFix
class ImplicitAssertionInspection : AbstractAssertJInspection() {
companion object {
private const val DISPLAY_NAME = "Asserting implicitly covered conditions"
private const val DELETE_IMPLICIT_DESCRIPTION_TEMPLATE = "Delete implicit %s() covered by %s()"
private const val SURPLUS_ASSERTION_MESSAGE = "Implicit %s() assertion is covered by %s()"
private val IS_PRESENT = CallMatcher.instanceCall(AssertJClassNames.ABSTRACT_OPTIONAL_ASSERT_CLASSNAME, MethodNames.IS_PRESENT, MethodNames.IS_NOT_EMPTY)
.parameterCount(0)!!
private val IS_NOT_PRESENT = CallMatcher.instanceCall(AssertJClassNames.ABSTRACT_OPTIONAL_ASSERT_CLASSNAME, MethodNames.IS_NOT_PRESENT, MethodNames.IS_EMPTY)
.parameterCount(0)!!
private val OPTIONAL_CONTAINS =
CallMatcher.instanceCall(
AssertJClassNames.ABSTRACT_OPTIONAL_ASSERT_CLASSNAME,
MethodNames.CONTAINS, MethodNames.CONTAINS_SAME,
"hasValue", "hasValueSatisfying", "containsInstanceOf"
).parameterCount(1)!!
private val OBJECT_ENUMERABLE_ANY_CONTENT_ASSERTIONS = CallMatcher.instanceCall(
AssertJClassNames.OBJECT_ENUMERABLE_ASSERT_INTERFACE,
MethodNames.CONTAINS, "containsOnly", "containsOnlyNulls", "containsOnlyOnce",
"containsExactly", "containsExactlyInAnyOrder", "containsExactlyInAnyOrderElementsOf",
"containsAll", "containsAnyOf",
"containsAnyElementsOf", "containsExactlyElementsOf", "containsOnlyElementsOf",
"isSubsetOf", "containsSequence", "containsSubsequence",
"doesNotContainSequence", "doesNotContainSubsequence", "doesNotContain",
"doesNotContainAnyElementsOf", "doesNotHaveDuplicates",
"startsWith", "endsWith", "containsNull", "doesNotContainNull",
"are", "areNot", "have", "doNotHave", "areAtLeastOne", "areAtLeast", "areAtMost", "areExactly",
"haveAtLeastOne", "haveAtLeast", "haveAtMost", "haveExactly",
"doesNotHave", "doesNotHaveSameClassAs",
"hasAtLeastOneElementOfType", "hasOnlyElementsOfType", "hasOnlyElementsOfTypes",
"doesNotHaveAnyElementsOfTypes",
"has", "doesNotHave",
"hasOnlyOneElementSatisfying", "hasSameElementsAs",
"allMatch", "allSatisfy", "anyMatch", "anySatisfy", "noneMatch", "noneSatisfy"
)!!
private val OBJECT_ENUMERABLE_AT_LEAST_ONE_CONTENT_ASSERTIONS = CallMatcher.instanceCall(
AssertJClassNames.OBJECT_ENUMERABLE_ASSERT_INTERFACE,
"containsOnlyNulls",
"startsWith", "endsWith", "containsNull",
"areAtLeastOne",
"haveAtLeastOne",
"hasAtLeastOneElementOfType",
"anyMatch", "anySatisfy"
)!!
private val ENUMERABLE_NON_NULL_ASSERTIONS = CallMatcher.instanceCall(
AssertJClassNames.ENUMERABLE_ASSERT_INTERFACE,
MethodNames.IS_EMPTY, MethodNames.IS_NOT_EMPTY,
MethodNames.HAS_SIZE, MethodNames.HAS_SIZE_GREATER_THAN, MethodNames.HAS_SIZE_GREATER_THAN_OR_EQUAL_TO,
MethodNames.HAS_SIZE_LESS_THAN, MethodNames.HAS_SIZE_LESS_THAN_OR_EQUAL_TO,
"hasSizeBetween", MethodNames.HAS_SAME_SIZE_AS
)!!
private val ENUMERABLE_AT_LEAST_ONE_CONTENT_ASSERTIONS = CallMatcher.instanceCall(
AssertJClassNames.ENUMERABLE_ASSERT_INTERFACE,
MethodNames.HAS_SIZE, MethodNames.HAS_SIZE_GREATER_THAN,
MethodNames.HAS_SAME_SIZE_AS
)!!
private val NON_NULL_CORE_ASSERTIONS = CallMatcher.instanceCall(
AssertJClassNames.ASSERT_INTERFACE,
"isInstanceOf", "isInstanceOfSatisfying", "isInstanceOfAny", "isExactlyInstanceOf", "isOfAnyClassIn",
"isNotInstanceOf", "isNotInstanceOfAny", "isNotExactlyInstanceOf", "isNotOfAnyClassIn",
"hasSameClassAs", "doesNotHaveSameClassAs",
"hasToString", "hasSameHashCodeAs"
)!!
private val GUAVA_IS_PRESENT = CallMatcher.instanceCall(AssertJClassNames.GUAVA_OPTIONAL_ASSERTIONS_CLASSNAME, MethodNames.IS_PRESENT)
.parameterCount(0)!!
private val GUAVA_IS_ABSENT = CallMatcher.instanceCall(AssertJClassNames.GUAVA_OPTIONAL_ASSERTIONS_CLASSNAME, MethodNames.IS_ABSENT)
.parameterCount(0)!!
private val GUAVA_OPTIONAL_CONTAINS = CallMatcher.instanceCall(
AssertJClassNames.GUAVA_OPTIONAL_ASSERTIONS_CLASSNAME,
MethodNames.CONTAINS, "extractingValue", "extractingCharSequence"
)!!
private val MAPPINGS = listOf(
IS_NOT_NULL to CallMatcher.anyOf(
NON_NULL_CORE_ASSERTIONS,
ENUMERABLE_NON_NULL_ASSERTIONS,
OBJECT_ENUMERABLE_ANY_CONTENT_ASSERTIONS,
IS_PRESENT, IS_NOT_PRESENT, OPTIONAL_CONTAINS,
GUAVA_IS_PRESENT, GUAVA_IS_ABSENT, GUAVA_OPTIONAL_CONTAINS
)!!,
IS_NOT_EMPTY to CallMatcher.anyOf(
ENUMERABLE_AT_LEAST_ONE_CONTENT_ASSERTIONS,
OBJECT_ENUMERABLE_AT_LEAST_ONE_CONTENT_ASSERTIONS
)!!,
IS_PRESENT to OPTIONAL_CONTAINS,
GUAVA_IS_PRESENT to GUAVA_OPTIONAL_CONTAINS
)
}
override fun getDisplayName() = DISPLAY_NAME
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
return object : JavaElementVisitor() {
override fun visitMethodCallExpression(expression: PsiMethodCallExpression) {
super.visitMethodCallExpression(expression)
if (!expression.hasAssertThat()) {
return
}
val mapping = MAPPINGS.firstOrNull { it.first.test(expression) } ?: return
val followupExpression = expression.findFluentCallTo(mapping.second) ?: return
val redundantName = getOriginalMethodName(expression) ?: return
val followupName = getOriginalMethodName(followupExpression) ?: return
val description = DELETE_IMPLICIT_DESCRIPTION_TEMPLATE.format(redundantName, followupName)
val quickFix = DeleteMethodCallQuickFix(description)
val textRange = TextRange(expression.qualifierExpression.textLength, expression.textLength)
holder.registerProblem(expression, textRange, SURPLUS_ASSERTION_MESSAGE.format(redundantName, followupName), quickFix)
}
}
}
}

View File

@ -0,0 +1,23 @@
package de.platon42.intellij.plugins.cajon.quickfixes
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiMethodCallExpression
import de.platon42.intellij.plugins.cajon.qualifierExpression
class DeleteMethodCallQuickFix(description: String) : AbstractCommonQuickFix(description) {
companion object {
private const val DELETE_METHOD_DESCRIPTION = "Delete unnecessary method calls"
}
override fun getFamilyName(): String {
return DELETE_METHOD_DESCRIPTION
}
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val methodCallExpression = descriptor.startElement as? PsiMethodCallExpression ?: return
methodCallExpression.replace(methodCallExpression.qualifierExpression)
}
}

View File

@ -55,6 +55,9 @@
<localInspection groupPath="Java" shortName="AssertThatGuavaOptional" enabledByDefault="true" level="WARNING"
implementationClass="de.platon42.intellij.plugins.cajon.inspections.AssertThatGuavaOptionalInspection"/>
<localInspection groupPath="Java" shortName="ImplicitAssertion" enabledByDefault="true" level="WARNING"
implementationClass="de.platon42.intellij.plugins.cajon.inspections.ImplicitAssertionInspection"/>
<localInspection groupPath="Java" shortName="JUnitAssertToAssertJ" enabledByDefault="true" level="WARNING"
implementationClass="de.platon42.intellij.plugins.cajon.inspections.JUnitAssertToAssertJInspection"/>
</extensions>

View File

@ -0,0 +1,8 @@
<html>
<body>
Finds assertion method calls that are already implicitly covered by prior assertions.
<!-- tooltip end -->
This works for isNotNull(), isNotEmpty() and isPresent(). It does not cover all edge cases, such as .isNotNull().isNullOrEmpty()
or comparing against non-null literals and is conservative to not eliminate legitimate assertions.
</body>
</html>

View File

@ -1,9 +1,10 @@
<html>
<body>
Tries to convert most of the JUnit 4 assertions to AssertJ format.
Tries to convert most of the JUnit 4 assertions and assumptions to AssertJ format.
<!-- tooltip end -->
<br>Works for assertTrue(), assertFalse(), assertNull(), assertNotNull(), assertEquals(), assertNotEquals(), assertSame() assertNotSame(), assertArrayEquals().
Copes with variants with message and without, handles special versions for double and float types (including arrays).
Also converts assumeTrue(), assumeFalse(), assumeNotNull(), assumeNoException() to assumeThat().
<p>
Does not support Hamcrest-Matchers. If you need that kind of conversion, you might want to check out the Assertions2AssertJ plugin by Ric Emery.
</p>

View File

@ -0,0 +1,26 @@
package de.platon42.intellij.plugins.cajon.inspections
import com.intellij.testFramework.fixtures.JavaCodeInsightTestFixture
import de.platon42.intellij.jupiter.AddLocalJarToModule
import de.platon42.intellij.jupiter.MyFixture
import de.platon42.intellij.jupiter.TestDataSubPath
import de.platon42.intellij.plugins.cajon.AbstractCajonTest
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
@AddLocalJarToModule(com.google.common.base.Optional::class, org.assertj.guava.api.Assertions::class, Assertions::class)
internal class ImplicitAssertionInspectionTest : AbstractCajonTest() {
@Test
@TestDataSubPath("inspections/ImplicitAssertion")
internal fun implicit_assertions_can_be_removed(@MyFixture myFixture: JavaCodeInsightTestFixture) {
runTest {
myFixture.enableInspections(ImplicitAssertionInspection::class.java)
myFixture.configureByFile("ImplicitAssertionBefore.java")
executeQuickFixes(myFixture, Regex("Delete implicit isNotNull\\(\\) covered by .*"), 101)
executeQuickFixes(myFixture, Regex("Delete implicit isNotEmpty\\(\\) covered by .*"), 17)
executeQuickFixes(myFixture, Regex("Delete implicit isPresent\\(\\) covered by .*"), 8)
myFixture.checkResultByFile("ImplicitAssertionAfter.java")
}
}
}

View File

@ -0,0 +1,288 @@
import org.assertj.core.api.Condition;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
public class ImplicitAssertion {
private void implicitAssertion() {
List<String> list = new ArrayList<>();
List<String> moreStrings = new ArrayList<>();
Condition<String> stringCondition = new Condition<>();
Condition<List<? extends String>> listCondition = new Condition<>();
Consumer<String> stringConsumer = (it) -> {
};
String string = "foo";
com.google.common.base.Optional<String> guavaOptional = com.google.common.base.Optional.absent();
Optional<String> java8Optional = Optional.empty();
assertThat(string).isNotNull().isNullOrEmpty(); // could be equal to .isEmpty()
assertThat(string).isEmpty();
assertThat(string).isNotEmpty();
assertThat(string).hasSize(1);
assertThat(string).hasSizeGreaterThan(1);
assertThat(string).hasSizeGreaterThanOrEqualTo(1);
assertThat(string).hasSizeLessThan(1);
assertThat(string).hasSizeLessThanOrEqualTo(1);
assertThat(string).hasSizeBetween(1, 2);
assertThat(string).hasSameSizeAs(moreStrings);
assertThat(string).isNotNull().isEqualTo("bar");
assertThat(string).isNotNull().isNotEqualTo("bar");
assertThat(string).isNotNull().isSameAs("bar");
assertThat(string).isNotNull().isNotSameAs("bar");
assertThat(string).isNotNull().contains(string);
assertThat(string).isNotNull().containsOnlyOnce(string);
assertThat(string).isNotNull().isIn(string, "bar");
assertThat(string).isNotNull().isNotIn(string, "bar");
assertThat(string).isNotNull().doesNotContain(string, "bar");
assertThat(string).isNotNull().startsWith("bar");
assertThat(string).isNotNull().endsWith("bar");
assertThat(string).isNotNull().containsSequence(moreStrings);
assertThat(string).isNotNull().containsSubsequence(moreStrings);
assertThat(string).isNotNull().has(stringCondition);
assertThat(string).isNotNull().doesNotHave(stringCondition);
assertThat(string).isNotNull().is(stringCondition);
assertThat(string).isNotNull().isNot(stringCondition);
assertThat(string).hasToString(string);
assertThat(string).isInstanceOf(String.class);
assertThat(string).isNotInstanceOf(String.class);
assertThat(string).isExactlyInstanceOf(String.class);
assertThat(string).isNotExactlyInstanceOf(String.class);
assertThat(string).isInstanceOfAny(String.class);
assertThat(string).isNotInstanceOfAny(String.class);
assertThat(string).isInstanceOfSatisfying(String.class, stringConsumer);
assertThat(string).hasSameClassAs("bar");
assertThat(string).doesNotHaveSameClassAs("bar");
assertThat(string).isOfAnyClassIn(String.class, CharSequence.class);
assertThat(string).isNotOfAnyClassIn(String.class, CharSequence.class);
assertThat(string).isNotEmpty().isNullOrEmpty();
assertThat(string).isNotEmpty().isEmpty();
assertThat(string).isNotEmpty().isNotEmpty();
assertThat(string).hasSize(1);
assertThat(string).hasSizeGreaterThan(1);
assertThat(string).isNotEmpty().hasSizeGreaterThanOrEqualTo(1);
assertThat(string).isNotEmpty().hasSizeLessThan(1);
assertThat(string).isNotEmpty().hasSizeLessThanOrEqualTo(1);
assertThat(string).isNotEmpty().hasSizeBetween(1, 2);
assertThat(string).hasSameSizeAs(moreStrings);
assertThat(string).isNotEmpty().isEqualTo("bar");
assertThat(string).isNotEmpty().isNotEqualTo("bar");
assertThat(string).isNotEmpty().isSameAs("bar");
assertThat(string).isNotEmpty().isNotSameAs("bar");
assertThat(string).isNotEmpty().contains(string);
assertThat(string).isNotEmpty().containsOnlyOnce(string);
assertThat(string).isNotEmpty().isIn(string, "bar");
assertThat(string).isNotEmpty().isNotIn(string, "bar");
assertThat(string).isNotEmpty().doesNotContain(string, "bar");
assertThat(string).isNotEmpty().startsWith("bar");
assertThat(string).isNotEmpty().endsWith("bar");
assertThat(string).isNotEmpty().containsSequence(moreStrings);
assertThat(string).isNotEmpty().containsSubsequence(moreStrings);
assertThat(string).isNotEmpty().has(stringCondition);
assertThat(string).isNotEmpty().doesNotHave(stringCondition);
assertThat(string).isNotEmpty().is(stringCondition);
assertThat(string).isNotEmpty().isNot(stringCondition);
assertThat(string).isNotEmpty().hasToString(string);
assertThat(string).isNotEmpty().isInstanceOf(String.class);
assertThat(string).isNotEmpty().isNotInstanceOf(String.class);
assertThat(string).isNotEmpty().isExactlyInstanceOf(String.class);
assertThat(string).isNotEmpty().isNotExactlyInstanceOf(String.class);
assertThat(string).isNotEmpty().isInstanceOfAny(String.class);
assertThat(string).isNotEmpty().isNotInstanceOfAny(String.class);
assertThat(string).isNotEmpty().isInstanceOfSatisfying(String.class, stringConsumer);
assertThat(string).isNotEmpty().hasSameClassAs("bar");
assertThat(string).isNotEmpty().doesNotHaveSameClassAs("bar");
assertThat(string).isNotEmpty().isOfAnyClassIn(String.class, CharSequence.class);
assertThat(string).isNotEmpty().isNotOfAnyClassIn(String.class, CharSequence.class);
assertThat(list).isNotNull().isNullOrEmpty();
assertThat(list).isEmpty();
assertThat(list).isNotEmpty();
assertThat(list).hasSize(1);
assertThat(list).hasSizeGreaterThan(1);
assertThat(list).hasSizeGreaterThanOrEqualTo(1);
assertThat(list).hasSizeLessThan(1);
assertThat(list).hasSizeLessThanOrEqualTo(1);
assertThat(list).hasSizeBetween(1, 2);
assertThat(list).hasSameSizeAs(moreStrings);
assertThat(list).isNotNull().isEqualTo(moreStrings);
assertThat(list).isNotNull().isNotEqualTo(moreStrings);
assertThat(list).isNotNull().isSameAs(moreStrings);
assertThat(list).isNotNull().isNotSameAs(moreStrings);
assertThat(list).contains(string);
assertThat(list).containsOnly(string);
assertThat(list).containsOnlyOnce(string);
assertThat(list).containsOnlyNulls();
assertThat(list).doesNotContainNull();
assertThat(list).containsExactly(string, "bar");
assertThat(list).containsExactlyInAnyOrder(string, "bar");
assertThat(list).containsAnyOf(string, "bar");
assertThat(list).containsAll(moreStrings);
assertThat(list).containsExactlyInAnyOrderElementsOf(moreStrings);
assertThat(list).isNotNull().isIn(string, "bar");
assertThat(list).isNotNull().isNotIn(string, "bar");
assertThat(list).doesNotContain(string, "bar");
assertThat(list).hasSameElementsAs(moreStrings);
assertThat(list).containsAnyElementsOf(moreStrings);
assertThat(list).containsExactlyElementsOf(moreStrings);
assertThat(list).containsOnlyElementsOf(moreStrings);
assertThat(list).doesNotContainAnyElementsOf(moreStrings);
assertThat(list).isSubsetOf(moreStrings);
assertThat(list).startsWith(string, "bar");
assertThat(list).endsWith(string, "bar");
assertThat(list).doesNotHaveDuplicates();
assertThat(list).containsSequence(moreStrings);
assertThat(list).containsSubsequence(moreStrings);
assertThat(list).doesNotContainSequence(moreStrings);
assertThat(list).doesNotContainSubsequence(moreStrings);
assertThat(list).are(stringCondition);
assertThat(list).areNot(stringCondition);
assertThat(list).have(stringCondition);
assertThat(list).doNotHave(stringCondition);
assertThat(list).areAtLeastOne(stringCondition);
assertThat(list).areAtLeast(1, stringCondition);
assertThat(list).areAtMost(1, stringCondition);
assertThat(list).areExactly(1, stringCondition);
assertThat(list).hasOnlyOneElementSatisfying(stringConsumer);
assertThat(list).haveAtLeastOne(stringCondition);
assertThat(list).haveAtLeast(1, stringCondition);
assertThat(list).haveAtMost(1, stringCondition);
assertThat(list).haveExactly(1, stringCondition);
assertThat(list).hasAtLeastOneElementOfType(String.class);
assertThat(list).hasOnlyElementsOfType(String.class);
assertThat(list).hasOnlyElementsOfTypes(String.class);
assertThat(list).doesNotHaveAnyElementsOfTypes(String.class);
assertThat(list).hasOnlyElementsOfTypes(String.class);
assertThat(list).has(listCondition);
assertThat(list).doesNotHave(listCondition);
assertThat(list).isNotNull().is(listCondition);
assertThat(list).isNotNull().isNot(listCondition);
assertThat(list).hasToString(string);
assertThat(list).isInstanceOf(String.class);
assertThat(list).isNotInstanceOf(String.class);
assertThat(list).isExactlyInstanceOf(String.class);
assertThat(list).isNotExactlyInstanceOf(String.class);
assertThat(list).isInstanceOfAny(String.class);
assertThat(list).isNotInstanceOfAny(String.class);
assertThat(list).noneMatch(it -> true);
assertThat(list).isInstanceOfSatisfying(String.class, stringConsumer);
assertThat(list).hasSameClassAs("bar");
assertThat(list).doesNotHaveSameClassAs("bar");
assertThat(list).isOfAnyClassIn(String.class, CharSequence.class);
assertThat(list).isNotOfAnyClassIn(String.class, CharSequence.class);
assertThat(list).isNotEmpty().isNullOrEmpty();
assertThat(list).isNotEmpty().isEmpty();
assertThat(list).isNotEmpty().isNotEmpty();
assertThat(list).hasSize(1);
assertThat(list).hasSizeGreaterThan(1);
assertThat(list).isNotEmpty().hasSizeGreaterThanOrEqualTo(1);
assertThat(list).isNotEmpty().hasSizeLessThan(1);
assertThat(list).isNotEmpty().hasSizeLessThanOrEqualTo(1);
assertThat(list).isNotEmpty().hasSizeBetween(1, 2);
assertThat(list).hasSameSizeAs(moreStrings);
assertThat(list).isNotEmpty().isEqualTo(moreStrings);
assertThat(list).isNotEmpty().isNotEqualTo(moreStrings);
assertThat(list).isNotEmpty().isSameAs(moreStrings);
assertThat(list).isNotEmpty().isNotSameAs(moreStrings);
assertThat(list).isNotEmpty().contains(string);
assertThat(list).isNotEmpty().containsOnly(string);
assertThat(list).isNotEmpty().containsOnlyOnce(string);
assertThat(list).containsOnlyNulls();
assertThat(list).isNotEmpty().doesNotContainNull();
assertThat(list).isNotEmpty().containsExactly(string, "bar");
assertThat(list).isNotEmpty().containsExactlyInAnyOrder(string, "bar");
assertThat(list).isNotEmpty().containsAnyOf(string, "bar");
assertThat(list).isNotEmpty().containsAll(moreStrings);
assertThat(list).isNotEmpty().containsExactlyInAnyOrderElementsOf(moreStrings);
assertThat(list).isNotEmpty().isIn(string, "bar");
assertThat(list).isNotEmpty().isNotIn(string, "bar");
assertThat(list).isNotEmpty().doesNotContain(string, "bar");
assertThat(list).isNotEmpty().hasSameElementsAs(moreStrings);
assertThat(list).isNotEmpty().containsAnyElementsOf(moreStrings);
assertThat(list).isNotEmpty().containsExactlyElementsOf(moreStrings);
assertThat(list).isNotEmpty().containsOnlyElementsOf(moreStrings);
assertThat(list).isNotEmpty().doesNotContainAnyElementsOf(moreStrings);
assertThat(list).isNotEmpty().isSubsetOf(moreStrings);
assertThat(list).startsWith(string, "bar");
assertThat(list).endsWith(string, "bar");
assertThat(list).isNotEmpty().doesNotHaveDuplicates();
assertThat(list).isNotEmpty().containsSequence(moreStrings);
assertThat(list).isNotEmpty().containsSubsequence(moreStrings);
assertThat(list).isNotEmpty().doesNotContainSequence(moreStrings);
assertThat(list).isNotEmpty().doesNotContainSubsequence(moreStrings);
assertThat(list).isNotEmpty().are(stringCondition);
assertThat(list).isNotEmpty().areNot(stringCondition);
assertThat(list).isNotEmpty().have(stringCondition);
assertThat(list).isNotEmpty().doNotHave(stringCondition);
assertThat(list).areAtLeastOne(stringCondition);
assertThat(list).isNotEmpty().areAtLeast(1, stringCondition);
assertThat(list).isNotEmpty().areAtMost(1, stringCondition);
assertThat(list).isNotEmpty().areExactly(1, stringCondition);
assertThat(list).isNotEmpty().hasOnlyOneElementSatisfying(stringConsumer);
assertThat(list).haveAtLeastOne(stringCondition);
assertThat(list).isNotEmpty().haveAtLeast(1, stringCondition);
assertThat(list).isNotEmpty().haveAtMost(1, stringCondition);
assertThat(list).isNotEmpty().haveExactly(1, stringCondition);
assertThat(list).hasAtLeastOneElementOfType(String.class);
assertThat(list).isNotEmpty().hasOnlyElementsOfType(String.class);
assertThat(list).isNotEmpty().hasOnlyElementsOfTypes(String.class);
assertThat(list).isNotEmpty().doesNotHaveAnyElementsOfTypes(String.class);
assertThat(list).isNotEmpty().hasOnlyElementsOfTypes(String.class);
assertThat(list).isNotEmpty().has(listCondition);
assertThat(list).isNotEmpty().doesNotHave(listCondition);
assertThat(list).isNotEmpty().is(listCondition);
assertThat(list).isNotEmpty().isNot(listCondition);
assertThat(list).isNotEmpty().hasToString(string);
assertThat(list).isNotEmpty().isInstanceOf(String.class);
assertThat(list).isNotEmpty().isNotInstanceOf(String.class);
assertThat(list).isNotEmpty().isExactlyInstanceOf(String.class);
assertThat(list).isNotEmpty().isNotExactlyInstanceOf(String.class);
assertThat(list).isNotEmpty().isInstanceOfAny(String.class);
assertThat(list).isNotEmpty().isNotInstanceOfAny(String.class);
assertThat(list).isNotEmpty().noneMatch(it -> true);
assertThat(list).isNotEmpty().isInstanceOfSatisfying(String.class, stringConsumer);
assertThat(list).isNotEmpty().hasSameClassAs("bar");
assertThat(list).isNotEmpty().doesNotHaveSameClassAs("bar");
assertThat(list).isNotEmpty().isOfAnyClassIn(String.class, CharSequence.class);
assertThat(list).isNotEmpty().isNotOfAnyClassIn(String.class, CharSequence.class);
assertThat(java8Optional).isPresent();
assertThat(java8Optional).isNotPresent();
assertThat(java8Optional).isEmpty();
assertThat(java8Optional).isNotEmpty();
assertThat(java8Optional).contains("foo");
assertThat(java8Optional).containsSame("foo");
assertThat(java8Optional).hasValue("foo");
assertThat(java8Optional).containsInstanceOf(String.class);
assertThat(java8Optional).hasValueSatisfying(stringCondition);
assertThat(java8Optional).contains("foo");
assertThat(java8Optional).containsSame("foo");
assertThat(java8Optional).hasValue("foo");
assertThat(java8Optional).containsInstanceOf(String.class);
assertThat(java8Optional).hasValueSatisfying(stringCondition);
assertThat(java8Optional).contains("foo");
assertThat(java8Optional).containsSame("foo");
assertThat(java8Optional).hasValue("foo");
assertThat(java8Optional).containsInstanceOf(String.class);
assertThat(java8Optional).hasValueSatisfying(stringCondition);
assertThat(guavaOptional).isPresent();
assertThat(guavaOptional).isAbsent();
assertThat(guavaOptional).contains("foo");
assertThat(guavaOptional).extractingValue().isEqualTo("foo");
assertThat(guavaOptional).extractingCharSequence().isEqualTo("foo");
assertThat(guavaOptional).contains("foo");
assertThat(guavaOptional).extractingValue().isEqualTo("foo");
assertThat(guavaOptional).extractingCharSequence().isEqualTo("foo");
}
}

View File

@ -0,0 +1,288 @@
import org.assertj.core.api.Condition;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.guava.api.Assertions.assertThat;
public class ImplicitAssertion {
private void implicitAssertion() {
List<String> list = new ArrayList<>();
List<String> moreStrings = new ArrayList<>();
Condition<String> stringCondition = new Condition<>();
Condition<List<? extends String>> listCondition = new Condition<>();
Consumer<String> stringConsumer = (it) -> {
};
String string = "foo";
com.google.common.base.Optional<String> guavaOptional = com.google.common.base.Optional.absent();
Optional<String> java8Optional = Optional.empty();
assertThat(string).isNotNull().isNullOrEmpty(); // could be equal to .isEmpty()
assertThat(string).isNotNull().isEmpty();
assertThat(string).isNotNull().isNotEmpty();
assertThat(string).isNotNull().hasSize(1);
assertThat(string).isNotNull().hasSizeGreaterThan(1);
assertThat(string).isNotNull().hasSizeGreaterThanOrEqualTo(1);
assertThat(string).isNotNull().hasSizeLessThan(1);
assertThat(string).isNotNull().hasSizeLessThanOrEqualTo(1);
assertThat(string).isNotNull().hasSizeBetween(1, 2);
assertThat(string).isNotNull().hasSameSizeAs(moreStrings);
assertThat(string).isNotNull().isEqualTo("bar");
assertThat(string).isNotNull().isNotEqualTo("bar");
assertThat(string).isNotNull().isSameAs("bar");
assertThat(string).isNotNull().isNotSameAs("bar");
assertThat(string).isNotNull().contains(string);
assertThat(string).isNotNull().containsOnlyOnce(string);
assertThat(string).isNotNull().isIn(string, "bar");
assertThat(string).isNotNull().isNotIn(string, "bar");
assertThat(string).isNotNull().doesNotContain(string, "bar");
assertThat(string).isNotNull().startsWith("bar");
assertThat(string).isNotNull().endsWith("bar");
assertThat(string).isNotNull().containsSequence(moreStrings);
assertThat(string).isNotNull().containsSubsequence(moreStrings);
assertThat(string).isNotNull().has(stringCondition);
assertThat(string).isNotNull().doesNotHave(stringCondition);
assertThat(string).isNotNull().is(stringCondition);
assertThat(string).isNotNull().isNot(stringCondition);
assertThat(string).isNotNull().hasToString(string);
assertThat(string).isNotNull().isInstanceOf(String.class);
assertThat(string).isNotNull().isNotInstanceOf(String.class);
assertThat(string).isNotNull().isExactlyInstanceOf(String.class);
assertThat(string).isNotNull().isNotExactlyInstanceOf(String.class);
assertThat(string).isNotNull().isInstanceOfAny(String.class);
assertThat(string).isNotNull().isNotInstanceOfAny(String.class);
assertThat(string).isNotNull().isInstanceOfSatisfying(String.class, stringConsumer);
assertThat(string).isNotNull().hasSameClassAs("bar");
assertThat(string).isNotNull().doesNotHaveSameClassAs("bar");
assertThat(string).isNotNull().isOfAnyClassIn(String.class, CharSequence.class);
assertThat(string).isNotNull().isNotOfAnyClassIn(String.class, CharSequence.class);
assertThat(string).isNotEmpty().isNullOrEmpty();
assertThat(string).isNotEmpty().isEmpty();
assertThat(string).isNotEmpty().isNotEmpty();
assertThat(string).isNotEmpty().hasSize(1);
assertThat(string).isNotEmpty().hasSizeGreaterThan(1);
assertThat(string).isNotEmpty().hasSizeGreaterThanOrEqualTo(1);
assertThat(string).isNotEmpty().hasSizeLessThan(1);
assertThat(string).isNotEmpty().hasSizeLessThanOrEqualTo(1);
assertThat(string).isNotEmpty().hasSizeBetween(1, 2);
assertThat(string).isNotEmpty().hasSameSizeAs(moreStrings);
assertThat(string).isNotEmpty().isEqualTo("bar");
assertThat(string).isNotEmpty().isNotEqualTo("bar");
assertThat(string).isNotEmpty().isSameAs("bar");
assertThat(string).isNotEmpty().isNotSameAs("bar");
assertThat(string).isNotEmpty().contains(string);
assertThat(string).isNotEmpty().containsOnlyOnce(string);
assertThat(string).isNotEmpty().isIn(string, "bar");
assertThat(string).isNotEmpty().isNotIn(string, "bar");
assertThat(string).isNotEmpty().doesNotContain(string, "bar");
assertThat(string).isNotEmpty().startsWith("bar");
assertThat(string).isNotEmpty().endsWith("bar");
assertThat(string).isNotEmpty().containsSequence(moreStrings);
assertThat(string).isNotEmpty().containsSubsequence(moreStrings);
assertThat(string).isNotEmpty().has(stringCondition);
assertThat(string).isNotEmpty().doesNotHave(stringCondition);
assertThat(string).isNotEmpty().is(stringCondition);
assertThat(string).isNotEmpty().isNot(stringCondition);
assertThat(string).isNotEmpty().hasToString(string);
assertThat(string).isNotEmpty().isInstanceOf(String.class);
assertThat(string).isNotEmpty().isNotInstanceOf(String.class);
assertThat(string).isNotEmpty().isExactlyInstanceOf(String.class);
assertThat(string).isNotEmpty().isNotExactlyInstanceOf(String.class);
assertThat(string).isNotEmpty().isInstanceOfAny(String.class);
assertThat(string).isNotEmpty().isNotInstanceOfAny(String.class);
assertThat(string).isNotEmpty().isInstanceOfSatisfying(String.class, stringConsumer);
assertThat(string).isNotEmpty().hasSameClassAs("bar");
assertThat(string).isNotEmpty().doesNotHaveSameClassAs("bar");
assertThat(string).isNotEmpty().isOfAnyClassIn(String.class, CharSequence.class);
assertThat(string).isNotEmpty().isNotOfAnyClassIn(String.class, CharSequence.class);
assertThat(list).isNotNull().isNullOrEmpty();
assertThat(list).isNotNull().isEmpty();
assertThat(list).isNotNull().isNotEmpty();
assertThat(list).isNotNull().hasSize(1);
assertThat(list).isNotNull().hasSizeGreaterThan(1);
assertThat(list).isNotNull().hasSizeGreaterThanOrEqualTo(1);
assertThat(list).isNotNull().hasSizeLessThan(1);
assertThat(list).isNotNull().hasSizeLessThanOrEqualTo(1);
assertThat(list).isNotNull().hasSizeBetween(1, 2);
assertThat(list).isNotNull().hasSameSizeAs(moreStrings);
assertThat(list).isNotNull().isEqualTo(moreStrings);
assertThat(list).isNotNull().isNotEqualTo(moreStrings);
assertThat(list).isNotNull().isSameAs(moreStrings);
assertThat(list).isNotNull().isNotSameAs(moreStrings);
assertThat(list).isNotNull().contains(string);
assertThat(list).isNotNull().containsOnly(string);
assertThat(list).isNotNull().containsOnlyOnce(string);
assertThat(list).isNotNull().containsOnlyNulls();
assertThat(list).isNotNull().doesNotContainNull();
assertThat(list).isNotNull().containsExactly(string, "bar");
assertThat(list).isNotNull().containsExactlyInAnyOrder(string, "bar");
assertThat(list).isNotNull().containsAnyOf(string, "bar");
assertThat(list).isNotNull().containsAll(moreStrings);
assertThat(list).isNotNull().containsExactlyInAnyOrderElementsOf(moreStrings);
assertThat(list).isNotNull().isIn(string, "bar");
assertThat(list).isNotNull().isNotIn(string, "bar");
assertThat(list).isNotNull().doesNotContain(string, "bar");
assertThat(list).isNotNull().hasSameElementsAs(moreStrings);
assertThat(list).isNotNull().containsAnyElementsOf(moreStrings);
assertThat(list).isNotNull().containsExactlyElementsOf(moreStrings);
assertThat(list).isNotNull().containsOnlyElementsOf(moreStrings);
assertThat(list).isNotNull().doesNotContainAnyElementsOf(moreStrings);
assertThat(list).isNotNull().isSubsetOf(moreStrings);
assertThat(list).isNotNull().startsWith(string, "bar");
assertThat(list).isNotNull().endsWith(string, "bar");
assertThat(list).isNotNull().doesNotHaveDuplicates();
assertThat(list).isNotNull().containsSequence(moreStrings);
assertThat(list).isNotNull().containsSubsequence(moreStrings);
assertThat(list).isNotNull().doesNotContainSequence(moreStrings);
assertThat(list).isNotNull().doesNotContainSubsequence(moreStrings);
assertThat(list).isNotNull().are(stringCondition);
assertThat(list).isNotNull().areNot(stringCondition);
assertThat(list).isNotNull().have(stringCondition);
assertThat(list).isNotNull().doNotHave(stringCondition);
assertThat(list).isNotNull().areAtLeastOne(stringCondition);
assertThat(list).isNotNull().areAtLeast(1, stringCondition);
assertThat(list).isNotNull().areAtMost(1, stringCondition);
assertThat(list).isNotNull().areExactly(1, stringCondition);
assertThat(list).isNotNull().hasOnlyOneElementSatisfying(stringConsumer);
assertThat(list).isNotNull().haveAtLeastOne(stringCondition);
assertThat(list).isNotNull().haveAtLeast(1, stringCondition);
assertThat(list).isNotNull().haveAtMost(1, stringCondition);
assertThat(list).isNotNull().haveExactly(1, stringCondition);
assertThat(list).isNotNull().hasAtLeastOneElementOfType(String.class);
assertThat(list).isNotNull().hasOnlyElementsOfType(String.class);
assertThat(list).isNotNull().hasOnlyElementsOfTypes(String.class);
assertThat(list).isNotNull().doesNotHaveAnyElementsOfTypes(String.class);
assertThat(list).isNotNull().hasOnlyElementsOfTypes(String.class);
assertThat(list).isNotNull().has(listCondition);
assertThat(list).isNotNull().doesNotHave(listCondition);
assertThat(list).isNotNull().is(listCondition);
assertThat(list).isNotNull().isNot(listCondition);
assertThat(list).isNotNull().hasToString(string);
assertThat(list).isNotNull().isInstanceOf(String.class);
assertThat(list).isNotNull().isNotInstanceOf(String.class);
assertThat(list).isNotNull().isExactlyInstanceOf(String.class);
assertThat(list).isNotNull().isNotExactlyInstanceOf(String.class);
assertThat(list).isNotNull().isInstanceOfAny(String.class);
assertThat(list).isNotNull().isNotInstanceOfAny(String.class);
assertThat(list).isNotNull().noneMatch(it -> true);
assertThat(list).isNotNull().isInstanceOfSatisfying(String.class, stringConsumer);
assertThat(list).isNotNull().hasSameClassAs("bar");
assertThat(list).isNotNull().doesNotHaveSameClassAs("bar");
assertThat(list).isNotNull().isOfAnyClassIn(String.class, CharSequence.class);
assertThat(list).isNotNull().isNotOfAnyClassIn(String.class, CharSequence.class);
assertThat(list).isNotEmpty().isNullOrEmpty();
assertThat(list).isNotEmpty().isEmpty();
assertThat(list).isNotEmpty().isNotEmpty();
assertThat(list).isNotEmpty().hasSize(1);
assertThat(list).isNotEmpty().hasSizeGreaterThan(1);
assertThat(list).isNotEmpty().hasSizeGreaterThanOrEqualTo(1);
assertThat(list).isNotEmpty().hasSizeLessThan(1);
assertThat(list).isNotEmpty().hasSizeLessThanOrEqualTo(1);
assertThat(list).isNotEmpty().hasSizeBetween(1, 2);
assertThat(list).isNotEmpty().hasSameSizeAs(moreStrings);
assertThat(list).isNotEmpty().isEqualTo(moreStrings);
assertThat(list).isNotEmpty().isNotEqualTo(moreStrings);
assertThat(list).isNotEmpty().isSameAs(moreStrings);
assertThat(list).isNotEmpty().isNotSameAs(moreStrings);
assertThat(list).isNotEmpty().contains(string);
assertThat(list).isNotEmpty().containsOnly(string);
assertThat(list).isNotEmpty().containsOnlyOnce(string);
assertThat(list).isNotEmpty().containsOnlyNulls();
assertThat(list).isNotEmpty().doesNotContainNull();
assertThat(list).isNotEmpty().containsExactly(string, "bar");
assertThat(list).isNotEmpty().containsExactlyInAnyOrder(string, "bar");
assertThat(list).isNotEmpty().containsAnyOf(string, "bar");
assertThat(list).isNotEmpty().containsAll(moreStrings);
assertThat(list).isNotEmpty().containsExactlyInAnyOrderElementsOf(moreStrings);
assertThat(list).isNotEmpty().isIn(string, "bar");
assertThat(list).isNotEmpty().isNotIn(string, "bar");
assertThat(list).isNotEmpty().doesNotContain(string, "bar");
assertThat(list).isNotEmpty().hasSameElementsAs(moreStrings);
assertThat(list).isNotEmpty().containsAnyElementsOf(moreStrings);
assertThat(list).isNotEmpty().containsExactlyElementsOf(moreStrings);
assertThat(list).isNotEmpty().containsOnlyElementsOf(moreStrings);
assertThat(list).isNotEmpty().doesNotContainAnyElementsOf(moreStrings);
assertThat(list).isNotEmpty().isSubsetOf(moreStrings);
assertThat(list).isNotEmpty().startsWith(string, "bar");
assertThat(list).isNotEmpty().endsWith(string, "bar");
assertThat(list).isNotEmpty().doesNotHaveDuplicates();
assertThat(list).isNotEmpty().containsSequence(moreStrings);
assertThat(list).isNotEmpty().containsSubsequence(moreStrings);
assertThat(list).isNotEmpty().doesNotContainSequence(moreStrings);
assertThat(list).isNotEmpty().doesNotContainSubsequence(moreStrings);
assertThat(list).isNotEmpty().are(stringCondition);
assertThat(list).isNotEmpty().areNot(stringCondition);
assertThat(list).isNotEmpty().have(stringCondition);
assertThat(list).isNotEmpty().doNotHave(stringCondition);
assertThat(list).isNotEmpty().areAtLeastOne(stringCondition);
assertThat(list).isNotEmpty().areAtLeast(1, stringCondition);
assertThat(list).isNotEmpty().areAtMost(1, stringCondition);
assertThat(list).isNotEmpty().areExactly(1, stringCondition);
assertThat(list).isNotEmpty().hasOnlyOneElementSatisfying(stringConsumer);
assertThat(list).isNotEmpty().haveAtLeastOne(stringCondition);
assertThat(list).isNotEmpty().haveAtLeast(1, stringCondition);
assertThat(list).isNotEmpty().haveAtMost(1, stringCondition);
assertThat(list).isNotEmpty().haveExactly(1, stringCondition);
assertThat(list).isNotEmpty().hasAtLeastOneElementOfType(String.class);
assertThat(list).isNotEmpty().hasOnlyElementsOfType(String.class);
assertThat(list).isNotEmpty().hasOnlyElementsOfTypes(String.class);
assertThat(list).isNotEmpty().doesNotHaveAnyElementsOfTypes(String.class);
assertThat(list).isNotEmpty().hasOnlyElementsOfTypes(String.class);
assertThat(list).isNotEmpty().has(listCondition);
assertThat(list).isNotEmpty().doesNotHave(listCondition);
assertThat(list).isNotEmpty().is(listCondition);
assertThat(list).isNotEmpty().isNot(listCondition);
assertThat(list).isNotEmpty().hasToString(string);
assertThat(list).isNotEmpty().isInstanceOf(String.class);
assertThat(list).isNotEmpty().isNotInstanceOf(String.class);
assertThat(list).isNotEmpty().isExactlyInstanceOf(String.class);
assertThat(list).isNotEmpty().isNotExactlyInstanceOf(String.class);
assertThat(list).isNotEmpty().isInstanceOfAny(String.class);
assertThat(list).isNotEmpty().isNotInstanceOfAny(String.class);
assertThat(list).isNotEmpty().noneMatch(it -> true);
assertThat(list).isNotEmpty().isInstanceOfSatisfying(String.class, stringConsumer);
assertThat(list).isNotEmpty().hasSameClassAs("bar");
assertThat(list).isNotEmpty().doesNotHaveSameClassAs("bar");
assertThat(list).isNotEmpty().isOfAnyClassIn(String.class, CharSequence.class);
assertThat(list).isNotEmpty().isNotOfAnyClassIn(String.class, CharSequence.class);
assertThat(java8Optional).isNotNull().isPresent();
assertThat(java8Optional).isNotNull().isNotPresent();
assertThat(java8Optional).isNotNull().isEmpty();
assertThat(java8Optional).isNotNull().isNotEmpty();
assertThat(java8Optional).isNotNull().contains("foo");
assertThat(java8Optional).isNotNull().containsSame("foo");
assertThat(java8Optional).isNotNull().hasValue("foo");
assertThat(java8Optional).isNotNull().containsInstanceOf(String.class);
assertThat(java8Optional).isNotNull().hasValueSatisfying(stringCondition);
assertThat(java8Optional).isPresent().contains("foo");
assertThat(java8Optional).isPresent().containsSame("foo");
assertThat(java8Optional).isPresent().hasValue("foo");
assertThat(java8Optional).isPresent().containsInstanceOf(String.class);
assertThat(java8Optional).isPresent().hasValueSatisfying(stringCondition);
assertThat(java8Optional).isNotEmpty().contains("foo");
assertThat(java8Optional).isNotEmpty().containsSame("foo");
assertThat(java8Optional).isNotEmpty().hasValue("foo");
assertThat(java8Optional).isNotEmpty().containsInstanceOf(String.class);
assertThat(java8Optional).isNotEmpty().hasValueSatisfying(stringCondition);
assertThat(guavaOptional).isNotNull().isPresent();
assertThat(guavaOptional).isNotNull().isAbsent();
assertThat(guavaOptional).isNotNull().contains("foo");
assertThat(guavaOptional).isNotNull().extractingValue().isEqualTo("foo");
assertThat(guavaOptional).isNotNull().extractingCharSequence().isEqualTo("foo");
assertThat(guavaOptional).isPresent().contains("foo");
assertThat(guavaOptional).isPresent().extractingValue().isEqualTo("foo");
assertThat(guavaOptional).isPresent().extractingCharSequence().isEqualTo("foo");
}
}