#421 - Polishing.
Simplify tests. Use ReflectionUtils.isVoid(…) where possible and simplify isVoid(…) flows. Original pull request: #422.
This commit is contained in:
@@ -144,10 +144,6 @@ public abstract class AbstractR2dbcQuery implements RepositoryQuery {
|
||||
return (q, t, c) -> q.rowsUpdated().then();
|
||||
}
|
||||
|
||||
if (KotlinDetector.isKotlinPresent() && Unit.class.isAssignableFrom(returnedType.getReturnedType())) {
|
||||
return (q, t, c) -> q.rowsUpdated().thenReturn(Unit.INSTANCE);
|
||||
}
|
||||
|
||||
return (q, t, c) -> q.rowsUpdated();
|
||||
}
|
||||
|
||||
|
||||
@@ -17,12 +17,9 @@ package org.springframework.data.r2dbc.repository.query;
|
||||
|
||||
import static org.springframework.data.repository.util.ClassUtils.*;
|
||||
|
||||
import kotlin.Unit;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.core.KotlinDetector;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -45,6 +42,7 @@ import org.springframework.data.repository.util.ReactiveWrapperConverters;
|
||||
import org.springframework.data.repository.util.ReactiveWrappers;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.data.util.Lazy;
|
||||
import org.springframework.data.util.ReflectionUtils;
|
||||
import org.springframework.data.util.TypeInformation;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -169,7 +167,7 @@ public class R2dbcQueryMethod extends QueryMethod {
|
||||
Class<?> domainClass = getDomainClass();
|
||||
|
||||
if (ClassUtils.isPrimitiveOrWrapper(returnedObjectType)
|
||||
|| KotlinDetector.isKotlinPresent() && Unit.class.isAssignableFrom(returnedObjectType)) {
|
||||
|| ReflectionUtils.isVoid(returnedObjectType)) {
|
||||
|
||||
this.metadata = new SimpleRelationalEntityMetadata<>((Class<Object>) domainClass,
|
||||
mappingContext.getRequiredPersistentEntity(domainClass));
|
||||
|
||||
@@ -17,8 +17,6 @@ package org.springframework.data.r2dbc.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import kotlin.Unit;
|
||||
|
||||
import io.r2dbc.spi.ConnectionFactory;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -50,7 +48,7 @@ import org.springframework.data.r2dbc.repository.support.R2dbcRepositoryFactory;
|
||||
import org.springframework.data.r2dbc.testing.R2dbcIntegrationTestSupport;
|
||||
import org.springframework.data.relational.core.mapping.Table;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
import org.springframework.data.repository.reactive.ReactiveSortingRepository;
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.transaction.reactive.TransactionalOperator;
|
||||
|
||||
@@ -58,7 +56,6 @@ import org.springframework.transaction.reactive.TransactionalOperator;
|
||||
* Abstract base class for integration tests for {@link LegoSetRepository} using {@link R2dbcRepositoryFactory}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Stephen Cohen
|
||||
*/
|
||||
public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcIntegrationTestSupport {
|
||||
|
||||
@@ -314,40 +311,6 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // gh-421
|
||||
public void shouldDeleteAndReturnSuccess() {
|
||||
|
||||
shouldInsertNewItems();
|
||||
|
||||
repository.deleteByManualAndReturnSuccess(12) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(true) //
|
||||
.verifyComplete();
|
||||
|
||||
repository.findAll() //
|
||||
.map(LegoSet::getManual) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(13) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // gh-421
|
||||
public void shouldDeleteAndReturnKotlinUnit() {
|
||||
|
||||
shouldInsertNewItems();
|
||||
|
||||
repository.deleteByManualAndReturnKotlinUnit(12) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(Unit.INSTANCE) //
|
||||
.verifyComplete();
|
||||
|
||||
repository.findAll() //
|
||||
.map(LegoSet::getManual) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(13) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
private Condition<? super Object> numberOf(int expected) {
|
||||
return new Condition<>(it -> {
|
||||
return it instanceof Number && ((Number) it).intValue() == expected;
|
||||
@@ -355,7 +318,7 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
|
||||
}
|
||||
|
||||
@NoRepositoryBean
|
||||
interface LegoSetRepository extends ReactiveSortingRepository<LegoSet, Integer> {
|
||||
interface LegoSetRepository extends ReactiveCrudRepository<LegoSet, Integer> {
|
||||
|
||||
Flux<LegoSet> findByNameContains(String name);
|
||||
|
||||
@@ -381,14 +344,6 @@ public abstract class AbstractR2dbcRepositoryIntegrationTests extends R2dbcInteg
|
||||
@Query("DELETE from legoset")
|
||||
Mono<Integer> deleteAllAndReturnCount();
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE from legoset where manual = :manual")
|
||||
Mono<Boolean> deleteByManualAndReturnSuccess(int manual);
|
||||
|
||||
@Modifying
|
||||
@Query("DELETE from legoset where manual = :manual")
|
||||
Mono<Unit> deleteByManualAndReturnKotlinUnit(int manual);
|
||||
|
||||
Mono<Integer> countByNameContains(String namePart);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user