Skip to content
Permalink
Browse files

DATAJPA-1064 - Adapt to changes in Mockito 2.7.

  • Loading branch information...
odrotbohm committed Mar 23, 2017
1 parent 3a558fe commit 06aaa447ce3883b2705901341de319a04a62c2f3
Showing with 77 additions and 65 deletions.
  1. +7 −2 src/main/java/org/springframework/data/jpa/repository/query/ParameterBinder.java
  2. +2 −0 src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java
  3. +7 −3 src/main/java/org/springframework/data/jpa/repository/query/StringQueryParameterBinder.java
  4. +7 −7 src/test/java/org/springframework/data/jpa/convert/QueryByExamplePredicateBuilderUnitTests.java
  5. +1 −1 src/test/java/org/springframework/data/jpa/domain/SpecificationsUnitTests.java
  6. +1 −1 src/test/java/org/springframework/data/jpa/mapping/JpaPersistentPropertyImplUnitTests.java
  7. +2 −2 src/test/java/org/springframework/data/jpa/repository/CrudMethodMetadataUnitTests.java
  8. +1 −1 src/test/java/org/springframework/data/jpa/repository/config/JpaAuditingRegistrarUnitTests.java
  9. +1 −1 ...st/java/org/springframework/data/jpa/repository/config/JpaRepositoryConfigExtensionUnitTests.java
  10. +1 −1 src/test/java/org/springframework/data/jpa/repository/query/AbstractJpaQueryTests.java
  11. +1 −1 ...va/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQueryIntegrationTests.java
  12. +1 −1 src/test/java/org/springframework/data/jpa/repository/query/ExpressionBasedStringQueryUnitTests.java
  13. +1 −1 src/test/java/org/springframework/data/jpa/repository/query/Jpa21UtilsUnitTests.java
  14. +7 −5 src/test/java/org/springframework/data/jpa/repository/query/JpaQueryExecutionUnitTests.java
  15. +2 −2 src/test/java/org/springframework/data/jpa/repository/query/JpaQueryLookupStrategyUnitTests.java
  16. +2 −2 src/test/java/org/springframework/data/jpa/repository/query/JpaQueryMethodUnitTests.java
  17. +6 −3 src/test/java/org/springframework/data/jpa/repository/query/NamedQueryUnitTests.java
  18. +2 −2 src/test/java/org/springframework/data/jpa/repository/query/ParameterBinderUnitTests.java
  19. +4 −5 src/test/java/org/springframework/data/jpa/repository/query/SimpleJpaQueryUnitTests.java
  20. +1 −1 ...t/java/org/springframework/data/jpa/repository/query/StoredProcedureAttributeSourceUnitTests.java
  21. +1 −1 src/test/java/org/springframework/data/jpa/repository/query/TupleConverterUnitTests.java
  22. +1 −1 ...framework/data/jpa/repository/support/CrudMethodMetadataPopulatingMethodInterceptorUnitTests.java
  23. +1 −1 ...st/java/org/springframework/data/jpa/repository/support/JpaEntityInformationSupportUnitTests.java
  24. +2 −2 .../java/org/springframework/data/jpa/repository/support/JpaMetamodelEntityInformationUnitTests.java
  25. +4 −4 ...ava/org/springframework/data/jpa/repository/support/JpaPersistableEntityInformationUnitTests.java
  26. +5 −8 src/test/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryBeanUnitTests.java
  27. +2 −2 src/test/java/org/springframework/data/jpa/repository/support/JpaRepositoryFactoryUnitTests.java
  28. +2 −2 src/test/java/org/springframework/data/jpa/repository/support/SimpleJpaRepositoryUnitTests.java
  29. +1 −1 .../org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessorUnitTests.java
  30. +1 −1 src/test/java/org/springframework/data/jpa/support/MergingPersistenceUnitManagerUnitTests.java
@@ -86,11 +86,13 @@ public Sort getSort() {
/**
* Binds the parameters to the given {@link Query}.
*
* @param query
* @param query must not be {@literal null}.
* @return
*/
public <T extends Query> T bind(T query) {

Assert.notNull(query, "Query must not be null!");

int bindableParameterIndex = 0;
int queryParameterPosition = 1;

@@ -150,10 +152,13 @@ protected void bind(Query query, JpaParameter parameter, Object value, int posit
/**
* Binds the parameters to the given query and applies special parameter types (e.g. pagination).
*
* @param query
* @param query must not be {@literal null}.
* @return
*/
public Query bindAndPrepare(Query query) {

Assert.notNull(query, "Query must not be null!");

return bindAndPrepare(query, parameters);
}

@@ -451,6 +451,8 @@ public static String createCountQueryFor(String originalQuery, String countProje
*/
public static boolean hasNamedParameter(Query query) {

Assert.notNull(query, "Query must not be null!");

for (Parameter<?> parameter : query.getParameters()) {

String name = parameter.getName();
@@ -67,13 +67,17 @@ protected void bind(Query jpaQuery, JpaParameter methodParameter, Object value,
*
* @param jpaQuery must not be {@literal null}.
* @param position
* @param methodParameter must not be {@literal null}.
* @param parameter must not be {@literal null}.
* @return the {@link ParameterBinding} for the given parameters or {@literal null} if none available.
*/
private ParameterBinding getBindingFor(Query jpaQuery, int position, Parameter methodParameter) {
private ParameterBinding getBindingFor(Query jpaQuery, int position, Parameter parameter) {

Assert.notNull(jpaQuery, "Query must not be null!");
Assert.notNull(parameter, "Parameter must not be null!");

if (hasNamedParameter(jpaQuery)) {
return query.getBindingFor(methodParameter.getName().orElseThrow(() -> new IllegalArgumentException("Parameter needs to be named!")));
return query.getBindingFor(
parameter.getName().orElseThrow(() -> new IllegalArgumentException("Parameter needs to be named!")));
}

try {
@@ -17,7 +17,7 @@

import static org.hamcrest.core.IsEqual.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.domain.Example.*;

@@ -43,9 +43,9 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.ArgumentMatchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.util.ObjectUtils;
@@ -57,7 +57,7 @@
* @author Mark Paluch
* @author Oliver Gierke
*/
@RunWith(MockitoJUnitRunner.class)
@RunWith(MockitoJUnitRunner.Silent.class)
@SuppressWarnings({ "rawtypes", "unchecked" })
public class QueryByExamplePredicateBuilderUnitTests {

@@ -112,8 +112,8 @@ public void setUp() {

doReturn(expressionMock).when(cb).literal(any(Boolean.class));
doReturn(truePredicate).when(cb).isTrue(eq(expressionMock));
doReturn(andPredicate).when(cb).and(Matchers.<Predicate>anyVararg());
doReturn(orPredicate).when(cb).or(Matchers.<Predicate>anyVararg());
doReturn(andPredicate).when(cb).and(ArgumentMatchers.any());
doReturn(orPredicate).when(cb).or(ArgumentMatchers.any());
}

@Test(expected = IllegalArgumentException.class) // DATAJPA-218
@@ -184,7 +184,7 @@ public void orConcatenatesPredicatesIfMatcherSpecifies() {

assertThat(QueryByExamplePredicateBuilder.getPredicate(root, cb, example), equalTo(orPredicate));

verify(cb, times(1)).or(Matchers.<Predicate>anyVararg());
verify(cb, times(1)).or(ArgumentMatchers.any());
}

static class Person {
@@ -32,7 +32,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

/**
* @author Oliver Gierke
@@ -38,7 +38,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.annotation.AccessType.Type;
import org.springframework.data.annotation.Version;
import org.springframework.data.util.ClassTypeInformation;
@@ -15,7 +15,7 @@
*/
package org.springframework.data.jpa.repository;

import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.io.Serializable;
@@ -34,7 +34,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.jpa.domain.sample.QRole;
import org.springframework.data.jpa.domain.sample.Role;
import org.springframework.data.jpa.repository.sample.RoleRepository;
@@ -18,7 +18,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.core.type.AnnotationMetadata;

@@ -32,7 +32,7 @@
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@@ -15,7 +15,7 @@
*/
package org.springframework.data.jpa.repository.query;

import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.jpa.support.EntityManagerTestUtils.*;

@@ -15,7 +15,7 @@
*/
package org.springframework.data.jpa.repository.query;

import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.reflect.Method;
@@ -22,7 +22,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;

import org.springframework.expression.spel.standard.SpelExpressionParser;

@@ -15,7 +15,7 @@
*/
package org.springframework.data.jpa.repository.query;

import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import javax.persistence.EntityGraph;
@@ -17,7 +17,7 @@

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;

import java.util.Arrays;
@@ -32,7 +32,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.query.JpaQueryExecution.ModifyingExecution;
@@ -47,7 +47,7 @@
* @author Thomas Darimont
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
@RunWith(MockitoJUnitRunner.Silent.class)
public class JpaQueryExecutionUnitTests {

@Mock EntityManager em;
@@ -172,7 +172,8 @@ public void pagedExecutionShouldUseCountFromResultWithOffsetAndResultsWithinPage
}

@Test // DATAJPA-912
public void pagedExecutionShouldUseRequestCountFromResultWithOffsetAndResultsHitLowerPageSizeBounds() throws Exception {
public void pagedExecutionShouldUseRequestCountFromResultWithOffsetAndResultsHitLowerPageSizeBounds()
throws Exception {

Parameters<?, ?> parameters = new DefaultParameters(getClass().getMethod("sampleMethod", Pageable.class));
when(jpaQuery.createQuery(Mockito.any(Object[].class))).thenReturn(query);
@@ -187,7 +188,8 @@ public void pagedExecutionShouldUseRequestCountFromResultWithOffsetAndResultsHit
}

@Test // DATAJPA-912
public void pagedExecutionShouldUseRequestCountFromResultWithOffsetAndResultsHitUpperPageSizeBounds() throws Exception {
public void pagedExecutionShouldUseRequestCountFromResultWithOffsetAndResultsHitUpperPageSizeBounds()
throws Exception {

Parameters<?, ?> parameters = new DefaultParameters(getClass().getMethod("sampleMethod", Pageable.class));
when(jpaQuery.createQuery(Mockito.any(Object[].class))).thenReturn(query);
@@ -17,7 +17,7 @@

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.reflect.Method;
@@ -32,7 +32,7 @@
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.sample.User;
@@ -17,7 +17,7 @@

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.annotation.Retention;
@@ -33,7 +33,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -15,20 +15,21 @@
*/
package org.springframework.data.jpa.repository.query;

import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.reflect.Method;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.TypedQuery;
import javax.persistence.metamodel.Metamodel;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.provider.QueryExtractor;
@@ -80,12 +81,14 @@ public void rejectsPersistenceProviderIfIncapableOfExtractingQueriesAndPagebleBe
}

@Test // DATAJPA-142
@SuppressWarnings("unchecked")
public void doesNotRejectPersistenceProviderIfNamedCountQueryIsAvailable() {

when(extractor.canExtractQuery()).thenReturn(false);
JpaQueryMethod queryMethod = new JpaQueryMethod(method, metadata, projectionFactory, extractor);

when(em.createNamedQuery(queryMethod.getNamedCountQueryName())).thenReturn(null);
TypedQuery<Long> countQuery = mock(TypedQuery.class);
when(em.createNamedQuery(eq(queryMethod.getNamedCountQueryName()), eq(Long.class))).thenReturn(countQuery);
NamedQuery query = (NamedQuery) NamedQuery.lookupFrom(queryMethod, em);

query.doCreateCountQuery(new Object[1]);
@@ -18,7 +18,7 @@
import static javax.persistence.TemporalType.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.reflect.Method;
@@ -34,7 +34,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Temporal;
@@ -17,7 +17,7 @@

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.lang.reflect.Method;
@@ -37,7 +37,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
@@ -60,7 +60,7 @@
* @author Oliver Gierke
* @author Thomas Darimont
*/
@RunWith(MockitoJUnitRunner.class)
@RunWith(MockitoJUnitRunner.Silent.class)
public class SimpleJpaQueryUnitTests {

static final String USER_QUERY = "select u from User u";
@@ -138,8 +138,7 @@ public void discoversNativeQuery() throws Exception {

assertThat(jpaQuery instanceof NativeJpaQuery, is(true));

Class<?> type = Mockito.any();
when(em.createNativeQuery(Mockito.anyString(), type)).thenReturn(query);
when(em.createNativeQuery(anyString(), eq(User.class))).thenReturn(query);
when(metadata.getReturnedDomainClass(method)).thenReturn((Class) User.class);

jpaQuery.createQuery(new Object[] { "Matthews" });
@@ -30,7 +30,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.core.annotation.AliasFor;
import org.springframework.data.jpa.domain.sample.User;
import org.springframework.data.repository.query.Param;
@@ -28,7 +28,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.data.jpa.repository.query.AbstractJpaQuery.TupleConverter;
import org.springframework.data.projection.ProjectionFactory;
import org.springframework.data.repository.CrudRepository;
Oops, something went wrong.

0 comments on commit 06aaa44

Please sign in to comment.
You can’t perform that action at this time.