-
-
Notifications
You must be signed in to change notification settings - Fork 683
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add assertions for JDK YearMonth type (#3141)
(cherry picked from commit 5f93909)
- Loading branch information
1 parent
c867f23
commit 1b6aa54
Showing
37 changed files
with
2,088 additions
and
2 deletions.
There are no files selected for viewing
607 changes: 607 additions & 0 deletions
607
assertj-core/src/main/java/org/assertj/core/api/AbstractYearMonthAssert.java
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
32 changes: 32 additions & 0 deletions
32
assertj-core/src/main/java/org/assertj/core/api/YearMonthAssert.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,32 @@ | ||
/* | ||
* 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.api; | ||
|
||
import java.time.YearMonth; | ||
|
||
/** | ||
* Assertions for {@link YearMonth} type from new Date & Time API introduced in Java 8. | ||
* | ||
* @since 3.26.0 | ||
*/ | ||
public class YearMonthAssert extends AbstractYearMonthAssert<YearMonthAssert> { | ||
|
||
/** | ||
* Creates a new <code>{@link YearMonthAssert}</code>. | ||
* | ||
* @param actual the actual value to verify | ||
*/ | ||
protected YearMonthAssert(YearMonth actual) { | ||
super(actual, YearMonthAssert.class); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
assertj-core/src/main/java/org/assertj/core/error/ShouldBeCurrentYearMonth.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,37 @@ | ||
/* | ||
* 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; | ||
|
||
import java.time.YearMonth; | ||
|
||
/** | ||
* Creates an error message indicating that an assertion that verifies that a {@link java.time.YearMonth} | ||
* is the current one (matching year and month). | ||
* | ||
* @since 3.26.0 | ||
*/ | ||
public class ShouldBeCurrentYearMonth extends BasicErrorMessageFactory { | ||
|
||
/** | ||
* Creates a new <code>{@link ShouldBeCurrentYearMonth}</code>. | ||
* @param actual the actual value in the failed assertion. | ||
* @return the created {@code ErrorMessageFactory}. | ||
*/ | ||
public static ErrorMessageFactory shouldBeCurrentYearMonth(YearMonth actual) { | ||
return new ShouldBeCurrentYearMonth(actual); | ||
} | ||
|
||
private ShouldBeCurrentYearMonth(YearMonth actual) { | ||
super("%nExpecting actual:%n %s%nto be the current YearMonth but was not.", actual); | ||
} | ||
} |
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
37 changes: 37 additions & 0 deletions
37
...tj-core/src/test/java/org/assertj/core/api/Assertions_assertThat_with_YearMonth_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,37 @@ | ||
/* | ||
* 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.api; | ||
|
||
import java.time.YearMonth; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* Tests for <code>{@link Assertions#assertThat(YearMonth)}</code>. | ||
*/ | ||
class Assertions_assertThat_with_YearMonth_Test { | ||
|
||
@Test | ||
void should_create_Assert() { | ||
AbstractYearMonthAssert<?> assertions = Assertions.assertThat(YearMonth.now()); | ||
assertThat(assertions).isNotNull(); | ||
} | ||
|
||
@Test | ||
void should_pass_actual() { | ||
YearMonth yearMonth = YearMonth.now(); | ||
AbstractYearMonthAssert<?> assertions = Assertions.assertThat(yearMonth); | ||
assertThat(assertions.getActual()).isSameAs(yearMonth); | ||
} | ||
} |
Oops, something went wrong.