Skip to content

Commit

Permalink
Merge branch 'main' into gh-3368
Browse files Browse the repository at this point in the history
# Conflicts:
#	assertj-core/src/test/java/org/assertj/core/api/InstanceOfAssertFactoriesTest.java
  • Loading branch information
scordio committed Mar 24, 2024
2 parents bccf85c + 46630d7 commit bc39ef3
Show file tree
Hide file tree
Showing 50 changed files with 2,329 additions and 15 deletions.
8 changes: 4 additions & 4 deletions assertj-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.16.1</version>
<version>2.17.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.0.0-jre</version>
<version>33.1.0-jre</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -123,7 +123,7 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.15.8</version>
<version>3.16</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -197,7 +197,7 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.3.32</version>
<version>5.3.33</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions assertj-core/src/main/java/org/assertj/core/api/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalUnit;
import java.util.Collection;
import java.util.Date;
Expand Down Expand Up @@ -931,6 +933,17 @@ public static AbstractZonedDateTimeAssert<?> assertThat(ZonedDateTime actual) {
return AssertionsForClassTypes.assertThat(actual);
}

/**
* Creates a new instance of <code>{@link TemporalAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.26.0
*/
public static TemporalAssert assertThat(Temporal actual) {
return new TemporalAssert(actual);
}

/**
* Creates a new instance of <code>{@link LocalDateTimeAssert}</code>.
*
Expand Down Expand Up @@ -981,6 +994,17 @@ public static AbstractLocalDateAssert<?> assertThat(LocalDate actual) {
return AssertionsForClassTypes.assertThat(actual);
}

/**
* Creates a new instance of <code>{@link YearMonthAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.26.0
*/
public static AbstractYearMonthAssert<?> assertThat(YearMonth actual) {
return AssertionsForClassTypes.assertThat(actual);
}

/**
* Creates a new instance of <code>{@link InstantAssert}</code>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -669,6 +670,17 @@ public static AbstractLocalDateAssert<?> assertThat(LocalDate localDate) {
return new LocalDateAssert(localDate);
}

/**
* Creates a new instance of <code>{@link YearMonthAssert}</code>.
*
* @param yearMonth the actual value.
* @return the created assertion object.
* @since 3.26.0
*/
public static AbstractYearMonthAssert<?> assertThat(YearMonth yearMonth) {
return new YearMonthAssert(yearMonth);
}

/**
* Creates a new instance of <code>{@link InstantAssert}</code>.
*
Expand Down
24 changes: 24 additions & 0 deletions assertj-core/src/main/java/org/assertj/core/api/Assumptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
Expand Down Expand Up @@ -1330,6 +1332,17 @@ public static OptionalLongAssert assumeThat(OptionalLong actual) {
return asAssumption(OptionalLongAssert.class, OptionalLong.class, actual);
}

/**
* Creates a new instance of {@link TemporalAssert} assumption.
*
* @param actual the Temporal to test
* @return the created assumption for the given object.
* @since 3.26.0
*/
public static TemporalAssert assumeThat(Temporal actual) {
return asAssumption(TemporalAssert.class, Temporal.class, actual);
}

/**
* Creates a new instance of {@link ZonedDateTimeAssert} assumption.
*
Expand Down Expand Up @@ -1396,6 +1409,17 @@ public static AbstractLocalDateAssert<?> assumeThat(LocalDate actual) {
return asAssumption(LocalDateAssert.class, LocalDate.class, actual);
}

/**
* Creates a new instance of {@link YearMonthAssert} assumption.
*
* @param actual the YearMonth to test
* @return the created assumption for assertion object.
* @since 3.26.0
*/
public static AbstractYearMonthAssert<?> assumeThat(YearMonth actual) {
return asAssumption(YearMonthAssert.class, YearMonth.class, actual);
}

/**
* Creates a new instance of {@link InstantAssert} assumption.
*
Expand Down
24 changes: 24 additions & 0 deletions assertj-core/src/main/java/org/assertj/core/api/BDDAssertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalUnit;
import java.util.Collection;
import java.util.Date;
Expand Down Expand Up @@ -1460,6 +1462,17 @@ public static <T> ObjectAssert<T> thenWith(T actual, Consumer<T>... requirements
return then(actual).satisfies(requirements);
}

/**
* Creates a new instance of <code>{@link org.assertj.core.api.TemporalAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.26.0
*/
public static TemporalAssert then(Temporal actual) {
return assertThat(actual);
}

/**
* Creates a new instance of <code>{@link org.assertj.core.api.LocalDateAssert}</code>.
*
Expand All @@ -1470,6 +1483,17 @@ public static AbstractLocalDateAssert<?> then(LocalDate actual) {
return assertThat(actual);
}

/**
* Creates a new instance of <code>{@link org.assertj.core.api.YearMonthAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.26.0
*/
public static AbstractYearMonthAssert<?> then(YearMonth actual) {
return assertThat(actual);
}

/**
* Creates a new instance of <code>{@link org.assertj.core.api.LocalDateTimeAssert}</code>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.util.List;
import java.util.Optional;
import java.util.OptionalDouble;
Expand Down Expand Up @@ -128,6 +130,17 @@ default MatcherAssert then(Matcher actual) {
return proxy(MatcherAssert.class, Matcher.class, actual);
}

/**
* Creates a new instance of <code>{@link TemporalAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.26.0
*/
default TemporalAssert then(Temporal actual) {
return proxy(TemporalAssert.class, Temporal.class, actual);
}

/**
* Creates a new instance of <code>{@link LocalDateAssert}</code>.
*
Expand All @@ -138,6 +151,17 @@ default LocalDateAssert then(LocalDate actual) {
return proxy(LocalDateAssert.class, LocalDate.class, actual);
}

/**
* Creates a new instance of <code>{@link YearMonthAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.26.0
*/
default YearMonthAssert then(YearMonth actual) {
return proxy(YearMonthAssert.class, YearMonth.class, actual);
}

/**
* Creates a new instance of <code>{@link LocalDateTimeAssert}</code>.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
Expand Down Expand Up @@ -491,6 +493,13 @@ static <ELEMENT> InstanceOfAssertFactory<ELEMENT[][], Object2DArrayAssert<ELEMEN
InstanceOfAssertFactory<Date, AbstractDateAssert<?>> DATE = new InstanceOfAssertFactory<>(Date.class,
Assertions::assertThat);

/**
* {@link InstanceOfAssertFactory} for a {@link java.time.temporal.Temporal}.
* @since 3.26.0
*/
InstanceOfAssertFactory<Temporal, TemporalAssert> TEMPORAL = new InstanceOfAssertFactory<>(Temporal.class,
Assertions::assertThat);

/**
* {@link InstanceOfAssertFactory} for a {@link ZonedDateTime}.
*/
Expand Down Expand Up @@ -527,6 +536,14 @@ static <ELEMENT> InstanceOfAssertFactory<ELEMENT[][], Object2DArrayAssert<ELEMEN
InstanceOfAssertFactory<LocalDate, AbstractLocalDateAssert<?>> LOCAL_DATE = new InstanceOfAssertFactory<>(LocalDate.class,
Assertions::assertThat);

/**
* {@link InstanceOfAssertFactory} for a {@link LocalDate}.
*
* @since 3.26.0
*/
InstanceOfAssertFactory<YearMonth, AbstractYearMonthAssert<?>> YEAR_MONTH = new InstanceOfAssertFactory<>(YearMonth.class,
Assertions::assertThat);

/**
* {@link InstanceOfAssertFactory} for an {@link Instant}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.YearMonth;
import java.time.ZonedDateTime;
import java.time.temporal.Temporal;
import java.util.List;
import java.util.Optional;
import java.util.OptionalDouble;
Expand Down Expand Up @@ -137,6 +139,17 @@ default LocalDateAssert assertThat(LocalDate actual) {
return proxy(LocalDateAssert.class, LocalDate.class, actual);
}

/**
* Creates a new instance of <code>{@link YearMonthAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.26.0
*/
default YearMonthAssert assertThat(YearMonth actual) {
return proxy(YearMonthAssert.class, YearMonth.class, actual);
}

/**
* Creates a new instance of <code>{@link LocalDateTimeAssert}</code>.
*
Expand Down Expand Up @@ -414,4 +427,16 @@ default LongAdderAssert assertThat(LongAdder actual) {
return proxy(LongAdderAssert.class, LongAdder.class, actual);
}

/**
* Create assertion for {@link TemporalAssert}.
*
* @param actual the actual value.
*
* @return the created assertion object.
* @since 3.26.0
*/
default TemporalAssert assertThat(Temporal actual) {
return proxy(TemporalAssert.class, Temporal.class, actual);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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 org.assertj.core.data.TemporalOffset;

import java.time.temporal.Temporal;

public class TemporalAssert extends AbstractTemporalAssert<TemporalAssert, Temporal> {

public TemporalAssert(Temporal actual) {
super(actual, TemporalAssert.class);
}

@Override
public Temporal parse(String temporalAsString) {
throw new UnsupportedOperationException("This is not supported because there is no unique String representation of Temporal, this is available in concrete assertion temporal class like ZonedDateTimeAssert");
}

@Override
public TemporalAssert isCloseTo(String otherAsString, TemporalOffset<? super Temporal> offset) {
throw new UnsupportedOperationException("This is not supported because there is no unique String representation of Temporal, this is available in concrete assertion temporal class like ZonedDateTimeAssert");
}
}

0 comments on commit bc39ef3

Please sign in to comment.