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

Add createAssert(ValueProvider) to AssertFactory #3377

Merged
merged 23 commits into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
46b5a30
Expose expected `InstanceOfAssertFactory` type and raw type
scordio Feb 25, 2024
d6cb373
Workaround for https://github.com/siom79/japicmp/issues/384
scordio Feb 25, 2024
7e6b238
Enhance `InstanceOfAssertFactory` test coverage
scordio Feb 25, 2024
28152b4
Initial coverage for `InstanceOfAssertFactories`
scordio Mar 2, 2024
30a6131
Improve coverage for `InstanceOfAssertFactories`
scordio Mar 3, 2024
da56f61
Finish coverage for `InstanceOfAssertFactories`
scordio Mar 5, 2024
6852811
Merge branch 'main' into gh-3368
scordio Mar 5, 2024
cedcaef
Revert "Workaround for https://github.com/siom79/japicmp/issues/384"
scordio Mar 6, 2024
6d86a5f
Add `getType` to `AssertFactory`
scordio Mar 7, 2024
bccf85c
Revert "Add `getType` to `AssertFactory`"
scordio Mar 9, 2024
bc39ef3
Merge branch 'main' into gh-3368
scordio Mar 24, 2024
f14f01d
Add `createAssert(ValueProvider)`
scordio Mar 24, 2024
15726cb
Merge branch 'main' into gh-3368
scordio Mar 24, 2024
9492a7f
Start InstanceOfAssertFactories coverage for createAssert(ValueProvider)
scordio Mar 24, 2024
a2175c4
Improve Javadoc
scordio Mar 25, 2024
3967e54
Improve test coverage for `createAssert(ValueProvider)`
scordio Mar 30, 2024
d541ee4
Remove `getType` from `InstanceOfAssertFactory`
scordio Apr 8, 2024
d942430
Improve test coverage for `InstanceOfAssertFactory`
scordio Apr 11, 2024
a7cb7bb
Add integration tests for Spring `DefaultConversionService`
scordio Apr 12, 2024
a95df78
Merge branch 'refs/heads/main' into gh-3368
scordio Apr 12, 2024
985359e
Use `isPrivate`
scordio Apr 12, 2024
fd7e4d3
Improve Javadoc
scordio Apr 28, 2024
1b169a2
Improve Javadoc
scordio May 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ public SELF satisfies(Condition<? super ACTUAL> condition) {
@CheckReturnValue
public <ASSERT extends AbstractAssert<?, ?>> ASSERT asInstanceOf(InstanceOfAssertFactory<?, ASSERT> instanceOfAssertFactory) {
requireNonNull(instanceOfAssertFactory, shouldNotBeNull("instanceOfAssertFactory")::create);
objects.assertIsInstanceOf(info, actual, instanceOfAssertFactory.getType());
objects.assertIsInstanceOf(info, actual, instanceOfAssertFactory.getRawClass());
return (ASSERT) instanceOfAssertFactory.createAssert(actual).withAssertionState(myself);
}

Expand Down
26 changes: 23 additions & 3 deletions assertj-core/src/main/java/org/assertj/core/api/AssertFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
*/
package org.assertj.core.api;

import java.lang.reflect.Type;
import java.util.Optional;

/**
* A single method factory interface to create an {@link Assert} for a given value.
* This factory method typically wraps a call to <code>assertThat(actual)</code>
* A functional interface to create an {@link Assert} for a given value.
* <p>
* The factory typically wraps a call to <code>assertThat(actual)</code>
* to produce a concrete assert type {@code ASSERT} for the input element of type {@code T}.
* <p>
* This interface is typically used by navigation assertions on iterable types like {@link AbstractIterableAssert}
Expand All @@ -29,12 +33,28 @@
public interface AssertFactory<T, ASSERT extends Assert<?, ?>> {

/**
* Creates the custom {@link Assert} instance for the given element value.
* Create the custom {@link Assert} instance for the given element value.
* <p>
* Typically, this will just invoke <code>assertThat(actual)</code>
* @param actual the input value for the {@code Assert} instance
* @return returns the custom {@code Assert} instance for the given element value
*/
ASSERT createAssert(T actual);

/**
* Return the {@link Type} of the input this factory expects, or an empty {@code Optional}
* if the information is not available.
*
* @implSpec Overriding implementations providing a non-empty optional are required to
* return a {@code Type} instance consistent with the value of the factory type parameter {@link T}.
scordio marked this conversation as resolved.
Show resolved Hide resolved
*
* @implNote The default implementation always returns an empty {@code Optional}.
*
* @return the expected type, or an empty {@code Optional} if the information is not available.
* @since 3.26.0
*/
default Optional<Type> getType() {
return Optional.empty();
}

}