Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix javadoc options / Use legacy mode to overcome <source> level issue #3231

Closed
wants to merge 9 commits into from
6 changes: 6 additions & 0 deletions assertj-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@
<version>3.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
*/
package org.assertj.core.api;

import static org.assertj.core.error.ShouldBeEqual.shouldBeEqual;
import static org.assertj.core.error.ShouldBeFalse.shouldBeFalse;
import static org.assertj.core.error.ShouldBeTrue.shouldBeTrue;
import static org.assertj.core.error.ShouldNotBeEqual.shouldNotBeEqual;

import java.util.Comparator;

import org.assertj.core.internal.Booleans;
import org.assertj.core.internal.Failures;
import org.assertj.core.util.VisibleForTesting;

/**
* Base class for all implementations of assertions for {@link Boolean}s.
Expand All @@ -36,9 +36,6 @@
*/
public abstract class AbstractBooleanAssert<SELF extends AbstractBooleanAssert<SELF>> extends AbstractAssert<SELF, Boolean> {

@VisibleForTesting
Booleans booleans = Booleans.instance();

protected AbstractBooleanAssert(Boolean actual, Class<?> selfType) {
super(actual, selfType);
}
Expand All @@ -47,11 +44,11 @@ protected AbstractBooleanAssert(Boolean actual, Class<?> selfType) {
* Verifies that the actual value is {@code true}.
* <p>
* Example:
* <pre><code class='java'> // assertions will pass
* <pre><code class='java'> // assertions succeed:
* assertThat(true).isTrue();
* assertThat(Boolean.TRUE).isTrue();
*
* // assertions will fail
* // assertions fail:
* assertThat(false).isTrue();
* assertThat(Boolean.FALSE).isTrue();</code></pre>
*
Expand All @@ -69,11 +66,11 @@ public SELF isTrue() {
* Verifies that the actual value is {@code false}.
* <p>
* Example:
* <pre><code class='java'> // assertions will pass
* <pre><code class='java'> // assertions succeed:
* assertThat(false).isFalse();
* assertThat(Boolean.FALSE).isFalse();
*
* // assertions will fail
* // assertions fail:
* assertThat(true).isFalse();
* assertThat(Boolean.TRUE).isFalse();</code></pre>
*
Expand All @@ -91,11 +88,11 @@ public SELF isFalse() {
* Verifies that the actual value is equal to the given one.
* <p>
* Example:
* <pre><code class='java'> // assertions will pass
* <pre><code class='java'> // assertions succeed:
* assertThat(true).isEqualTo(true);
* assertThat(Boolean.FALSE).isEqualTo(false);
*
* // assertions will fail
* // assertions fail:
* assertThat(true).isEqualTo(false);
* assertThat(Boolean.TRUE).isEqualTo(false);</code></pre>
*
Expand All @@ -105,19 +102,20 @@ public SELF isFalse() {
* @throws AssertionError if the actual value is not equal to the given one.
*/
public SELF isEqualTo(boolean expected) {
booleans.assertEqual(info, actual, expected);
if (actual == null || actual != expected)
throw Failures.instance().failure(info, shouldBeEqual(actual, expected, info.representation()));
return myself;
}

/**
* Verifies that the actual value is not equal to the given one.
* <p>
* Example:
* <pre><code class='java'> // assertions will pass
* <pre><code class='java'> // assertions succeed:
* assertThat(true).isNotEqualTo(false);
* assertThat(Boolean.FALSE).isNotEqualTo(true);
*
* // assertions will fail
* // assertions fail:
* assertThat(true).isNotEqualTo(true);
* assertThat(Boolean.FALSE).isNotEqualTo(false);</code></pre>
*
Expand All @@ -127,7 +125,7 @@ public SELF isEqualTo(boolean expected) {
* @throws AssertionError if the actual value is equal to the given one.
*/
public SELF isNotEqualTo(boolean other) {
booleans.assertNotEqual(info, actual, other);
if (actual != null && actual == other) throwAssertionError(shouldNotBeEqual(actual, other));
return myself;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.assertj.core.api;

import static java.lang.Character.isWhitespace;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toCollection;
import static org.assertj.core.api.Assertions.contentOf;
Expand All @@ -28,6 +29,8 @@
import static org.assertj.core.error.ShouldNotBeBlank.shouldNotBeBlank;
import static org.assertj.core.error.ShouldNotContainAnyWhitespaces.shouldNotContainAnyWhitespaces;
import static org.assertj.core.error.ShouldNotContainOnlyWhitespaces.shouldNotContainOnlyWhitespaces;
import static org.assertj.core.error.ShouldNotEndWithWhitespaces.shouldNotEndWithWhitespaces;
import static org.assertj.core.error.ShouldNotStartWithWhitespaces.shouldNotStartWithWhitespaces;
import static org.assertj.core.internal.Strings.doCommonCheckForCharSequence;
import static org.assertj.core.internal.Strings.removeAllWhitespaces;
import static org.assertj.core.util.IterableUtil.toArray;
Expand Down Expand Up @@ -2153,6 +2156,62 @@ public SELF isVisible() {
return myself;
}

/**
* Verifies that the actual {@code CharSequence} does not start with whitespaces (as per
* {@link Character#isWhitespace(int)} definition), it also checks it is not null as a prerequisite.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed:
* assertThat(&quot;abc&quot;).doesNotStartWithWhitespaces();
* assertThat(&quot;abc &quot;).doesNotStartWithWhitespaces();
* assertThat(&quot;abc\t\t&quot;).doesNotStartWithWhitespaces();
* assertThat(&quot;&quot;).doesNotStartWithWhitespaces();
*
* // assertions fail:
* assertThat(&quot; abc&quot;).doesNotStartWithWhitespaces();
* assertThat(&quot; abc &quot;).doesNotStartWithWhitespaces();
* assertThat(&quot;\r\nabc&quot;).doesNotStartWithWhitespaces();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code CharSequence} starts with whitespace or is null.
* @see Character#isWhitespace(int)
* @since 3.26.0
*/
public SELF doesNotStartWithWhitespaces() {
isNotNull();
if (actual.length() > 0 && isWhitespace(actual.codePoints().findFirst().getAsInt()))
throwAssertionError(shouldNotStartWithWhitespaces(actual));
return myself;
}

/**
* Verifies that the actual {@code CharSequence} does not end with whitespaces (as per
* {@link Character#isWhitespace(int)} definition), it also checks it is not null as a prerequisite.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed:
* assertThat(&quot;abc&quot;).doesNotEndWithWhitespaces();
* assertThat(&quot; abc&quot;).doesNotEndWithWhitespaces();
* assertThat(&quot;\t\tabc&quot;).doesNotEndWithWhitespaces();
* assertThat(&quot;&quot;).doesNotEndWithWhitespaces();
*
* // assertions fail:
* assertThat(&quot;abc &quot;).doesNotEndWithWhitespaces();
* assertThat(&quot; abc &quot;).doesNotEndWithWhitespaces();
* assertThat(&quot;abc\r\n&quot;).doesNotEndWithWhitespaces();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual {@code CharSequence} ends with whitespace or is null.
* @see Character#isWhitespace(int)
* @since 3.26.0
*/
public SELF doesNotEndWithWhitespaces() {
isNotNull();
if (actual.length() > 0 && Character.isWhitespace(actual.codePoints().reduce((v1, v2) -> v2).getAsInt()))
throwAssertionError(shouldNotEndWithWhitespaces(actual));
return myself;
}

private static boolean isBlank(CharSequence actual) {
return isNullOrEmpty(actual) || strictlyContainsWhitespaces(actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static java.util.Collections.singleton;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.assertj.core.description.Description.mostRelevantDescription;
import static org.assertj.core.error.ShouldBeUnmodifiable.shouldBeUnmodifiable;
Expand All @@ -26,6 +27,7 @@

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
Expand Down Expand Up @@ -2219,4 +2221,26 @@ private static List<Object> flatten(Iterable<Object> collectionToFlatten) {
}
return result;
}

/**
* <p>Returns an {@link AbstractCollectionAssert} to make assertions on the values of the map</p>
*
* <p><strong>Example</strong></p>
* <pre><code class='java'> TolkienCharacter pippin = new TolkienCharacter("Pippin", 28, HOBBIT);
* TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
* TolkienCharacter merry = new TolkienCharacter("Merry", 36, HOBBIT);
*
* Map&lt;String, TolkienCharacter&gt; characters = mapOf(entry("Pippin", pippin),
* entry("Frodo", frodo),
* entry("Merry", merry));
* assertThat(characters).values()
* .contains(frodo, pippin, merry); </code></pre>
* @return An {@link AbstractCollectionAssert} to make collections assertion only on map values.
* @throws NullPointerException if the map under test is null
* @since 3.26.0
*/
public AbstractCollectionAssert<?, Collection<? extends V>, V, ObjectAssert<V>> values() {
requireNonNull(actual, "Can not extract values from a null map.");
return assertThat(actual.values());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,27 +115,30 @@ public SELF isNotEmpty() {
}

/**
* Verifies that the actual {@link java.util.OptionalDouble} has the value in argument.
* Verifies that the actual {@link java.util.OptionalDouble} has the value in argument. The check is consistent
* with {@link java.util.OptionalDouble#equals(Object)} since 3.26.0.
* <p>
* Assertion will pass :
* <pre><code class='java'> assertThat(OptionalDouble.of(8.0)).hasValue(8.0);
* <pre><code class='java'> // assertions succeed:
* assertThat(OptionalDouble.of(8.0)).hasValue(8.0);
* assertThat(OptionalDouble.of(8.0)).hasValue(Double.valueOf(8.0));
* assertThat(OptionalDouble.of(Double.NaN)).hasValue(Double.NaN); </code></pre>
* <p>
* Assertion will fail :
* <pre><code class='java'> assertThat(OptionalDouble.empty()).hasValue(8.0);
* assertThat(OptionalDouble.of(Double.NaN)).hasValue(Double.NaN);
* assertThat(OptionalDouble.of(Double.POSITIVE_INFINITY)).hasValue(Double.POSITIVE_INFINITY);
* assertThat(OptionalDouble.of(Double.NEGATIVE_INFINITY)).hasValue(Double.NEGATIVE_INFINITY);
*
* // assertions fail:
* assertThat(OptionalDouble.empty()).hasValue(8.0);
* assertThat(OptionalDouble.of(7)).hasValue(8.0);</code></pre>
*
* @param expectedValue the expected value inside the {@link java.util.OptionalDouble}.
* @return this assertion object.
* @throws java.lang.AssertionError if actual value is empty.
* @throws java.lang.AssertionError if actual is null.
* @throws java.lang.AssertionError if actual has not the value as expected.
* @throws java.lang.AssertionError if actual does not have the expected value.
*/
public SELF hasValue(double expectedValue) {
isNotNull();
if (!actual.isPresent()) throwAssertionError(shouldContain(expectedValue));
if (expectedValue != actual.getAsDouble())
if (Double.compare(expectedValue, actual.getAsDouble()) != 0)
throw Failures.instance().failure(info, shouldContain(actual, expectedValue), actual.getAsDouble(), expectedValue);
return myself;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@
import java.util.Comparator;
import java.util.concurrent.atomic.AtomicBoolean;

import org.assertj.core.internal.Booleans;
import org.assertj.core.util.VisibleForTesting;

public class AtomicBooleanAssert extends AbstractAssert<AtomicBooleanAssert, AtomicBoolean> {

@VisibleForTesting
Booleans booleans = Booleans.instance();

public AtomicBooleanAssert(AtomicBoolean actual) {
super(actual, AtomicBooleanAssert.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public CollectionAssert(Collection<? extends ELEMENT> actual) {

@Override
protected ObjectAssert<ELEMENT> toAssert(ELEMENT value, String description) {
return new ObjectAssertFactory<ELEMENT>().createAssert(value).as(description);
return new ObjectAssert<>(value).as(description);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class IterableAssert<ELEMENT> extends
FactoryBasedNavigableIterableAssert<IterableAssert<ELEMENT>, Iterable<? extends ELEMENT>, ELEMENT, ObjectAssert<ELEMENT>> {

public IterableAssert(Iterable<? extends ELEMENT> actual) {
super(actual, IterableAssert.class, new ObjectAssertFactory<>());
super(actual, IterableAssert.class, ObjectAssert::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static ListAssert<Integer> assertThatIntStream(IntStream actual) {
}

public ListAssert(List<? extends ELEMENT> actual) {
super(actual, ListAssert.class, new ObjectAssertFactory<>());
super(actual, ListAssert.class, ObjectAssert::new);
}

public ListAssert(Stream<? extends ELEMENT> actual) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
package org.assertj.core.api;

/**
* @deprecated Use {@link Assertions#assertThat(Object)} instead.
*
* @since 2.5.0 / 3.5.0
*/
@Deprecated
public class ObjectAssertFactory<T> implements AssertFactory<T, ObjectAssert<T>> {

/** {@inheritDoc} */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ShouldHaveCauseInstance extends BasicErrorMessageFactory {
public static ErrorMessageFactory shouldHaveCauseInstance(Throwable actual,
Class<? extends Throwable> expectedCauseType) {
return actual.getCause() == null
? new ShouldHaveCauseInstance(expectedCauseType)
? new ShouldHaveCauseInstance(expectedCauseType, actual)
: new ShouldHaveCauseInstance(actual, expectedCauseType);
}

Expand All @@ -47,10 +47,10 @@ private ShouldHaveCauseInstance(Throwable actual, Class<? extends Throwable> exp
expectedCauseType, actual.getCause().getClass());
}

private ShouldHaveCauseInstance(Class<? extends Throwable> expectedCauseType) {
private ShouldHaveCauseInstance(Class<? extends Throwable> expectedCauseType, Throwable actual) {
super("%nExpecting a throwable with cause being an instance of:%n" +
" %s%n" +
"but current throwable has no cause.",
expectedCauseType);
"but current throwable has no cause.%n" +
"Throwable that failed the check:%n" + escapePercent(getStackTrace(actual)), expectedCauseType);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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-2024 the original author or authors.
*/
package org.assertj.core.error;

/**
* Creates an error message indicating that an assertion that verifies that a {@link CharSequence}
* does not end with whitespace characters.
*/
public class ShouldNotEndWithWhitespaces extends BasicErrorMessageFactory {

/**
* Creates a new <code>{@link ShouldNotEndWithWhitespaces}</code>.
* @param actual the actual value in the failed assertion.
* @return the created {@code ErrorMessageFactory}.
*/
public static ErrorMessageFactory shouldNotEndWithWhitespaces(CharSequence actual) {
return new ShouldNotEndWithWhitespaces(actual);
}

private ShouldNotEndWithWhitespaces(Object actual) {
super("%n" +
"Expecting string not to end with whitespaces but found one, string was:%n" +
" %s", actual);
}
}