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

Increase abstractassert test coverage #2527

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 43 additions & 23 deletions src/test/java/org/assertj/core/api/SoftAssertionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
import static org.assertj.core.api.Assertions.not;
import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.BDDAssertions.then;
import static org.assertj.core.api.InstanceOfAssertFactories.STRING;
import static org.assertj.core.api.InstanceOfAssertFactories.type;
import static org.assertj.core.api.InstanceOfAssertFactories.*;
import static org.assertj.core.api.SoftAssertions.assertSoftly;
import static org.assertj.core.data.TolkienCharacter.Race.ELF;
import static org.assertj.core.data.TolkienCharacter.Race.HOBBIT;
Expand Down Expand Up @@ -884,8 +883,9 @@ void should_work_with_comparable() {
softly.assertThat(example1).isEqualByComparingTo(example3);
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageContaining("123");
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageContaining("123");
}

@Test
Expand Down Expand Up @@ -1027,9 +1027,10 @@ void should_return_failure_after_fail_with_throwable() {
softly.fail(failureMessage, realCause);
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageStartingWith(failureMessage);
assertThat(errorsCollected.get(0).getCause()).isEqualTo(realCause);
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageStartingWith(failureMessage)
.cause().isEqualTo(realCause);
}

@Test
Expand All @@ -1038,8 +1039,20 @@ void should_return_failure_after_shouldHaveThrown() {
softly.shouldHaveThrown(IllegalArgumentException.class);
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageStartingWith("IllegalArgumentException should have been thrown");
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageStartingWith("IllegalArgumentException should have been thrown");
}

@Test
void should_return_failure_after_failBecauseExceptionWasNotThrown() {
// WHEN
softly.failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageStartingWith("IllegalArgumentException should have been thrown");
}

@Test
Expand Down Expand Up @@ -1929,8 +1942,9 @@ void class_soft_assertions_should_report_errors_on_final_methods() {
.hasAnnotations(SafeVarargs.class, VisibleForTesting.class);
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageContaining("SafeVarargs")
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageContaining("SafeVarargs")
.hasMessageContaining("VisibleForTesting");
}

Expand Down Expand Up @@ -2211,8 +2225,9 @@ void soft_assertions_should_work_with_zipSatisfy() {
.zipSatisfy(names, (n1, n2) -> softly.assertThat(n1).isNotEqualTo(n2));
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessage("[zipSatisfy] error message");
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessage("[zipSatisfy] error message");
}

@Test
Expand All @@ -2224,8 +2239,9 @@ void bug_1209() {
// THEN
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageContaining("%%E")
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageContaining("%%E")
.hasMessageContaining("to match pattern")
.hasMessageContaining("fffff");
}
Expand All @@ -2242,8 +2258,9 @@ void should_keep_representation_after_changing_the_object_under_test() {
.contains("ó");
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageContaining("unicode")
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageContaining("unicode")
.hasMessageContaining("\\u00f3");
}

Expand Down Expand Up @@ -2370,8 +2387,9 @@ void soft_assertions_should_work_with_satisfiesAnyOf() {
.satisfiesAnyOf(isHobbit, isMan);
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageContaining("[satisfiesAnyOf] ")
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageContaining("[satisfiesAnyOf] ")
.hasMessageContaining("HOBBIT")
.hasMessageContaining("ELF")
.hasMessageContaining("MAN");
Expand All @@ -2388,8 +2406,9 @@ void soft_assertions_should_work_with_satisfies() {
softly.assertThat(legolas).as("satisfies").satisfies(isHobbit, isElf, isMan);
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageContaining("[satisfies] ")
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageContaining("[satisfies] ")
.hasMessageContaining("HOBBIT")
.hasMessageContaining("MAN");
}
Expand All @@ -2409,8 +2428,9 @@ void soft_assertions_should_work_with_assertThatObject() {
.satisfiesAnyOf(isFirstHobbit, isFirstMan);
// THEN
List<Throwable> errorsCollected = softly.errorsCollected();
assertThat(errorsCollected).hasSize(1);
assertThat(errorsCollected.get(0)).hasMessageContaining("[assertThatObject#satisfiesAnyOf] ")
assertThat(errorsCollected)
.singleElement(as(THROWABLE))
.hasMessageContaining("[assertThatObject#satisfiesAnyOf] ")
.hasMessageContaining("HOBBIT")
.hasMessageContaining("ELF")
.hasMessageContaining("MAN");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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-2022 the original author or authors.
*/
package org.assertj.core.api.bigdecimal;

import org.assertj.core.api.BigDecimalAssert;
import org.assertj.core.api.BigDecimalAssertBaseTest;

import java.math.BigDecimal;

import static org.mockito.Mockito.verify;


/**
* Tests for <code>{@link BigDecimalAssert#isGreaterThanOrEqualTo(BigDecimal)}</code>.
*
* @author Sára Juhošová
*/
class BigDecimalAssert_isGreaterThanOrEqualTo_Test extends BigDecimalAssertBaseTest {

private final BigDecimal other = new BigDecimal(983);

@Override
protected BigDecimalAssert invoke_api_method() {
return assertions.isGreaterThanOrEqualTo(other);
}

@Override
protected void verify_internal_effects() {
verify(comparables).assertGreaterThanOrEqualTo(getInfo(assertions), getActual(assertions), other);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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-2022 the original author or authors.
*/
package org.assertj.core.api.bigdecimal;

import org.assertj.core.api.BigDecimalAssert;
import org.assertj.core.api.BigDecimalAssertBaseTest;
import org.assertj.core.data.Offset;

import java.math.BigDecimal;

import static org.assertj.core.data.Offset.offset;
import static org.mockito.Mockito.verify;


/**
* Tests for <code>{@link BigDecimalAssert#isLessThanOrEqualTo(BigDecimal)}</code>.
*
* @author Sára Juhošová
*/
class BigDecimalAssert_isLessThanOrEqualTo_Test extends BigDecimalAssertBaseTest {

private final BigDecimal other = new BigDecimal(322);

@Override
protected BigDecimalAssert invoke_api_method() {
return assertions.isLessThanOrEqualTo(other);
}

@Override
protected void verify_internal_effects() {
verify(comparables).assertLessThanOrEqualTo(getInfo(assertions), getActual(assertions), other);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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-2022 the original author or authors.
*/
package org.assertj.core.api.charsequence;

import org.assertj.core.api.CharSequenceAssert;
import org.assertj.core.api.CharSequenceAssertBaseTest;
import org.assertj.core.api.IntegerAssert;
import org.assertj.core.data.Offset;

import static org.mockito.Mockito.verify;

/**
* Tests for <code>{@link CharSequenceAssert#isEqualToNormalizingNewlines(CharSequence)}</code>.
*
* @author Sára Juhošová
*/
class CharSequenceAssert_isEqualToNormalizingNewLines_Test extends CharSequenceAssertBaseTest {

@Override
protected CharSequenceAssert invoke_api_method() {
return assertions.isEqualToNormalizingNewlines("harry potter\nhermione granger");
}

@Override
protected void verify_internal_effects() {
verify(strings).assertIsEqualToNormalizingNewlines(getInfo(assertions), getActual(assertions), "harry potter\nhermione granger");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.assertj.core.api.DoubleAssertBaseTest;
import org.assertj.core.data.Percentage;

class DoubleAssert_isCloseToPercentage_Test extends DoubleAssertBaseTest {
class DoubleAssert_isCloseToPercentage_Double_Test extends DoubleAssertBaseTest {

private final Percentage percentage = withPercentage(5.0);
private final Double value = 10.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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-2022 the original author or authors.
*/
package org.assertj.core.api.double_;

import org.assertj.core.api.DoubleAssert;
import org.assertj.core.api.DoubleAssertBaseTest;
import org.assertj.core.data.Offset;
import org.assertj.core.data.Percentage;

import static org.assertj.core.data.Percentage.withPercentage;
import static org.mockito.Mockito.verify;

/**
* Tests for <code>{@link DoubleAssert#isCloseTo(double, Percentage)}</code>.
*
* @author Sára Juhošová
*/
class DoubleAssert_isCloseToPercentage_double_Test extends DoubleAssertBaseTest {

private final Percentage percentage = withPercentage(6.0);
private final double value = 22.6;

@Override
protected DoubleAssert invoke_api_method() {
return assertions.isCloseTo(value, percentage);
}

@Override
protected void verify_internal_effects() {
verify(doubles).assertIsCloseToPercentage(getInfo(assertions), getActual(assertions), value, percentage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*
* @author Chris Arnott
*/
class DoubleAssert_isNotCloseToPercentage_Test extends DoubleAssertBaseTest {
class DoubleAssert_isNotCloseToPercentage_Double_Test extends DoubleAssertBaseTest {

private final Percentage percentage = withPercentage(5.0);
private final Double value = 10.0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* 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-2022 the original author or authors.
*/
package org.assertj.core.api.double_;

import org.assertj.core.api.DoubleAssert;
import org.assertj.core.api.DoubleAssertBaseTest;
import org.assertj.core.data.Percentage;

import static org.assertj.core.data.Percentage.withPercentage;
import static org.mockito.Mockito.verify;

/**
* Tests for <code>{@link DoubleAssert#isNotCloseTo(double, Percentage)}</code>.
*
* @author Sára Juhošová
*/
class DoubleAssert_isNotCloseToPercentage_double_Test extends DoubleAssertBaseTest {

private final Percentage percentage = withPercentage(5.4);
private final double value = 62.7;

@Override
protected DoubleAssert invoke_api_method() {
return assertions.isNotCloseTo(value, percentage);
}

@Override
protected void verify_internal_effects() {
verify(doubles).assertIsNotCloseToPercentage(getInfo(assertions), getActual(assertions), value, percentage);
}
}