-
-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
206 additions
and
10 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
46 changes: 46 additions & 0 deletions
46
assertj-core/src/main/java/org/assertj/core/error/ShouldHaveRecordComponents.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,46 @@ | ||
/* | ||
* 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.core.error; | ||
|
||
import java.util.Set; | ||
|
||
/** | ||
* Creates an error message indicating that an assertion that verifies that a class has record components failed. | ||
* | ||
* @author Louis Morgan | ||
*/ | ||
public class ShouldHaveRecordComponents extends BasicErrorMessageFactory { | ||
|
||
/** | ||
* Creates a new <code>{@link ShouldHaveRecordComponents}</code> | ||
* | ||
* @param actual the actual value in the failed assertion. | ||
* @param expected expected record components for this class | ||
* @param missing missing record components for this class | ||
* @return the created {@code ErrorMessageFactory}. | ||
*/ | ||
public static ErrorMessageFactory shouldHaveRecordComponents(Class<?> actual, Set<String> expected, Set<String> missing) { | ||
return new ShouldHaveRecordComponents(actual, expected, missing); | ||
} | ||
|
||
private ShouldHaveRecordComponents(Class<?> actual, Set<String> expected, Set<String> missing) { | ||
super("%nExpecting%n" + | ||
" %s%n" + | ||
"to have the following record components:%n" + | ||
" %s%n" + | ||
"but it doesn't have:%n" + | ||
" %s", | ||
actual, expected, missing); | ||
} | ||
|
||
} |
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
55 changes: 55 additions & 0 deletions
55
...core/src/test/java/org/assertj/core/api/classes/ClassAssert_hasRecordComponents_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,55 @@ | ||
/* | ||
* 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.core.api.classes; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static org.assertj.core.error.ShouldBeRecord.shouldBeRecord; | ||
import static org.assertj.core.error.ShouldNotBeNull.shouldNotBeNull; | ||
import static org.assertj.core.util.AssertionsUtil.expectAssertionError; | ||
|
||
import java.util.ArrayList; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
/** | ||
* @author Louis Morgan | ||
*/ | ||
class ClassAssert_hasRecordComponents_Test { | ||
|
||
@Test | ||
void should_fail_if_actual_is_null() { | ||
// GIVEN | ||
Class<?> actual = null; | ||
// WHEN | ||
AssertionError error = expectAssertionError(() -> assertThat(actual).hasRecordComponents("component")); | ||
// THEN | ||
then(error).hasMessage(shouldNotBeNull().create()); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(classes = { | ||
String.class, | ||
ArrayList.class, | ||
ValueSource.class | ||
}) | ||
void should_fail_if_actual_is_not_a_record(Class<?> actual) { | ||
// WHEN | ||
AssertionError error = expectAssertionError(() -> assertThat(actual).hasRecordComponents("component")); | ||
// THEN | ||
then(error).hasMessage(shouldBeRecord(actual).create()); | ||
} | ||
|
||
} |
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