Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ShouldNotBeNull(new factory method), Throwables(update of assertHasMe…
…ssageFindingMatch()), unit tests created and updated
- Loading branch information
Showing
9 changed files
with
141 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...va/org/assertj/core/internal/throwables/Throwables_assertHasMessageFindingMatch_Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* 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-2018 the original author or authors. | ||
*/ | ||
package org.assertj.core.internal.throwables; | ||
|
||
import org.assertj.core.api.AssertionInfo; | ||
import org.assertj.core.error.ShouldNotBeNull; | ||
import org.assertj.core.internal.ThrowablesBaseTest; | ||
import org.junit.Ignore; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.assertj.core.api.Assertions.assertThatNullPointerException; | ||
import static org.assertj.core.error.ShouldHaveMessageFindMatchingRegex.shouldHaveMessageFindMatchingRegex; | ||
import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; | ||
import static org.assertj.core.test.TestData.someInfo; | ||
import static org.mockito.Mockito.verify; | ||
|
||
/** | ||
* | ||
* @author David Haccoun | ||
*/ | ||
|
||
public class Throwables_assertHasMessageFindingMatch_Test extends ThrowablesBaseTest { | ||
|
||
static final String REGEX = "waiting for Foo"; | ||
|
||
@Test | ||
public void should_pass_if_throwable_message_matches_given_regex() { | ||
Throwable actual = new RuntimeException("Blablabla...\n" + | ||
"waiting for Foo" + | ||
"...blablabla...\n"); | ||
throwables.assertHasMessageFindingMatch(someInfo(), actual, REGEX); | ||
} | ||
|
||
@Test | ||
public void should_pass_if_throwable_message_is_empty_and_regex_is_too() { | ||
Throwable actual = new RuntimeException(""); | ||
throwables.assertHasMessageFindingMatch(someInfo(), actual, ""); | ||
} | ||
|
||
@Test | ||
public void should_fail_if_throwable_message_does_not_match_given_regex() { | ||
|
||
Throwable actual = new RuntimeException("Blablabla...\n" + | ||
"waiting for Bar" + | ||
"...blablabla...\n"); | ||
AssertionInfo info = someInfo(); | ||
assertThatExceptionOfType(AssertionError.class) | ||
.isThrownBy(() -> throwables.assertHasMessageFindingMatch(someInfo(), actual, REGEX)); | ||
verify(failures).failure(info, shouldHaveMessageFindMatchingRegex(actual, REGEX)); | ||
} | ||
|
||
@Test | ||
public void should_fail_if_given_regex_is_null() { | ||
assertThatNullPointerException() | ||
.isThrownBy(() -> throwables.assertHasMessageFindingMatch(someInfo(), actual, null)) | ||
.withMessage("regex must not be null"); | ||
} | ||
|
||
@Test | ||
public void should_fail_if_throwable_is_null() { | ||
AssertionInfo info = someInfo(); | ||
assertThatExceptionOfType(AssertionError.class) | ||
.isThrownBy(() -> throwables.assertHasMessageFindingMatch(someInfo(), null, REGEX)); | ||
verify(failures).failure(info, shouldNotBeNull()); | ||
} | ||
|
||
@Test | ||
public void should_fail_if_throwable_does_not_have_a_message() { | ||
actual = new RuntimeException(); | ||
AssertionInfo info = someInfo(); | ||
assertThatExceptionOfType(AssertionError.class) | ||
.isThrownBy(() -> throwables.assertHasMessageFindingMatch(someInfo(), actual, REGEX)); | ||
verify(failures).failure(info, ShouldNotBeNull.of("exception message of actual")); | ||
} | ||
|
||
} |