DATAMONGO-2351 - Polishing.
Fix broken tests and favor StepVerifier over block() for reactive ones. Original Pull Request: #781
This commit is contained in:
@@ -231,6 +231,7 @@ interface MongoQueryExecution {
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Artyom Gabeev
|
||||
* @author Christoph Strobl
|
||||
* @since 1.5
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@@ -254,7 +255,7 @@ interface MongoQueryExecution {
|
||||
}
|
||||
|
||||
DeleteResult writeResult = operations.remove(query, type, collectionName);
|
||||
return writeResult != null && writeResult.wasAcknowledged() ? writeResult.getDeletedCount() : 0L;
|
||||
return writeResult.wasAcknowledged() ? writeResult.getDeletedCount() : 0L;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,6 +96,8 @@ public class AbstractMongoQueryUnitTests {
|
||||
doReturn(executableFind).when(mongoOperationsMock).query(any());
|
||||
doReturn(withQueryMock).when(executableFind).as(any());
|
||||
doReturn(withQueryMock).when(withQueryMock).matching(any());
|
||||
|
||||
when(mongoOperationsMock.remove(any(), any(), anyString())).thenReturn(deleteResultMock);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-566
|
||||
@@ -128,7 +130,7 @@ public class AbstractMongoQueryUnitTests {
|
||||
public void testDeleteExecutionReturnsNrDocumentsDeletedFromWriteResult() {
|
||||
|
||||
when(deleteResultMock.getDeletedCount()).thenReturn(100L);
|
||||
when(mongoOperationsMock.remove(any(), eq(Person.class), eq("persons"))).thenReturn(deleteResultMock);
|
||||
when(deleteResultMock.wasAcknowledged()).thenReturn(true);
|
||||
|
||||
MongoQueryFake query = createQueryForMethod("deletePersonByLastname", String.class);
|
||||
query.setDeleteQuery(true);
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
@@ -174,26 +175,20 @@ public class MongoQueryExecutionUnitTests {
|
||||
|
||||
@Test // DATAMONGO-2351
|
||||
public void acknowledgedDeleteReturnsDeletedCount() {
|
||||
|
||||
when(mongoOperationsMock.remove(any(Query.class), any(Class.class), anyString()))
|
||||
.thenReturn(DeleteResult.acknowledged(10));
|
||||
|
||||
DeleteExecution execution = new DeleteExecution(mongoOperationsMock, queryMethod);
|
||||
Object result = execution.execute(new Query());
|
||||
|
||||
assertThat(result).isEqualTo(10L);
|
||||
|
||||
assertThat(new DeleteExecution(mongoOperationsMock, queryMethod).execute(new Query())).isEqualTo(10L);
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2351
|
||||
public void unacknowledgedDeleteReturnsZeroDeletedCount() {
|
||||
|
||||
when(mongoOperationsMock.remove(any(Query.class), any(Class.class), anyString()))
|
||||
.thenReturn(DeleteResult.unacknowledged());
|
||||
|
||||
DeleteExecution execution = new DeleteExecution(mongoOperationsMock, queryMethod);
|
||||
Object result = execution.execute(new Query());
|
||||
|
||||
assertThat(result).isEqualTo(0L);
|
||||
|
||||
assertThat(new DeleteExecution(mongoOperationsMock, queryMethod).execute(new Query())).isEqualTo(0L);
|
||||
}
|
||||
|
||||
interface PersonRepository extends Repository<Person, Long> {
|
||||
|
||||
@@ -17,10 +17,14 @@ package org.springframework.data.mongodb.repository.query;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
@@ -30,6 +34,7 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.reactivestreams.Publisher;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Range;
|
||||
@@ -106,24 +111,26 @@ public class ReactiveMongoQueryExecutionUnitTests {
|
||||
|
||||
@Test // DATAMONGO-2351
|
||||
public void acknowledgedDeleteReturnsDeletedCount() {
|
||||
|
||||
when(operations.remove(any(Query.class), any(Class.class), anyString()))
|
||||
.thenReturn(Mono.just(DeleteResult.acknowledged(10)));
|
||||
|
||||
DeleteExecution execution = new DeleteExecution(operations, method);
|
||||
Object result = ((Mono) execution.execute(new Query(), Class.class, "")).block();
|
||||
|
||||
assertThat(result).isEqualTo(10L);
|
||||
Mono.from((Publisher<Long>) new DeleteExecution(operations, method).execute(new Query(), Class.class, "")) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(10L) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAMONGO-2351
|
||||
public void unacknowledgedDeleteReturnsZeroDeletedCount() {
|
||||
|
||||
when(operations.remove(any(Query.class), any(Class.class), anyString()))
|
||||
.thenReturn(Mono.just(DeleteResult.unacknowledged()));
|
||||
|
||||
DeleteExecution execution = new DeleteExecution(operations, method);
|
||||
Object result = ((Mono) execution.execute(new Query(), Class.class, "")).block();
|
||||
|
||||
assertThat(result).isEqualTo(0L);
|
||||
Mono.from((Publisher<Long>) new DeleteExecution(operations, method).execute(new Query(), Class.class, "")) //
|
||||
.as(StepVerifier::create) //
|
||||
.expectNext(0L) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
interface GeoRepo {
|
||||
|
||||
Reference in New Issue
Block a user