Polish for #557.
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation.support;
|
||||
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalStateException;
|
||||
@@ -33,20 +32,20 @@ import org.apache.geode.cache.GemFireCache;
|
||||
import org.apache.geode.ra.GFConnection;
|
||||
import org.apache.geode.ra.GFConnectionFactory;
|
||||
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.slf4j.event.Level;
|
||||
|
||||
/**
|
||||
* {@link AbstractGemFireAsLastResourceAspectSupport} is an abstract base class encapsulating functionality common
|
||||
* to all AOP Aspect extensions/implementations involving the GemFire JCA ResourceAdapter object registered in
|
||||
* to all AOP Aspect extensions/implementations involving the Apache Geode JCA ResourceAdapter object registered in
|
||||
* the JNDI context of a managed environment.
|
||||
*
|
||||
* @author John Blum
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -26,8 +25,8 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -52,7 +51,7 @@ import org.springframework.data.gemfire.mapping.MappingPdxSerializer;
|
||||
import org.springframework.util.MethodInvoker;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link EnablePdx} and {@link PdxConfiguration}.
|
||||
* Unit Tests for {@link EnablePdx} and {@link PdxConfiguration}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -60,8 +59,6 @@ import org.springframework.util.MethodInvoker;
|
||||
* @see org.mockito.Spy
|
||||
* @see org.apache.geode.pdx.PdxSerializer
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.beans.factory.BeanFactory
|
||||
* @see org.springframework.data.gemfire.CacheFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.annotation.EnablePdx
|
||||
* @see org.springframework.data.gemfire.config.annotation.PdxConfiguration
|
||||
* @since 1.0.0
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -25,8 +24,8 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.data.gemfire.util.ArrayUtils.asArray;
|
||||
|
||||
@@ -52,17 +51,14 @@ import org.springframework.data.gemfire.mapping.annotation.Region;
|
||||
import org.springframework.data.gemfire.test.model.Person;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractAnnotationConfigSupport}.
|
||||
* Unit Tests for {@link AbstractAnnotationConfigSupport}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see java.lang.annotation.Annotation
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionRegistry
|
||||
* @see org.springframework.data.gemfire.config.annotation.support.AbstractAnnotationConfigSupport
|
||||
* @since 1.1.0
|
||||
*/
|
||||
@@ -76,7 +72,6 @@ public class AbstractAnnotationConfigSupportTests {
|
||||
this.support = spy(new TestAnnotationConfigSupport());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private BeanDefinition mockBeanDefinition(Class<?> beanClass) {
|
||||
|
||||
AbstractBeanDefinition mockBeanDefinition = mock(AbstractBeanDefinition.class, beanClass.getSimpleName());
|
||||
@@ -290,7 +285,7 @@ public class AbstractAnnotationConfigSupportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public void resolveBeanClassFromBeanDefinition() throws ClassNotFoundException {
|
||||
|
||||
AbstractBeanDefinition mockBeanDefinition = mock(AbstractBeanDefinition.class);
|
||||
@@ -336,8 +331,7 @@ public class AbstractAnnotationConfigSupportTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveBeanClassUsingThreadContextClassLoaderAndFactoryMethodReturnType()
|
||||
throws ClassNotFoundException {
|
||||
public void resolveBeanClassUsingThreadContextClassLoaderAndFactoryMethodReturnType() {
|
||||
|
||||
AnnotatedBeanDefinition mockBeanDefinition = mock(AnnotatedBeanDefinition.class);
|
||||
|
||||
@@ -537,7 +531,7 @@ public class AbstractAnnotationConfigSupportTests {
|
||||
|
||||
}
|
||||
|
||||
class TestAnnotationConfigSupport extends AbstractAnnotationConfigSupport {
|
||||
static class TestAnnotationConfigSupport extends AbstractAnnotationConfigSupport {
|
||||
|
||||
@Override
|
||||
protected Class<? extends Annotation> getAnnotationType() {
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.annotation.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -54,7 +53,7 @@ import org.apache.geode.cache.GemFireCache;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractGemFireAsLastResourceAspectSupport}.
|
||||
* Unit Tests for {@link AbstractGemFireAsLastResourceAspectSupport}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see javax.naming.Context
|
||||
@@ -420,22 +419,20 @@ public class AbstractGemFireAsLastResourceAspectSupportUnitTests {
|
||||
}
|
||||
|
||||
// TODO refactor this BS; damn you Mockito for your inability to match Varargs completely/reliably; WTF!
|
||||
protected static final class VariableArgumentMatcher<T> implements ArgumentMatcher<T>, VarargMatcher {
|
||||
static final class VariableArgumentMatcher<T> implements ArgumentMatcher<T>, VarargMatcher {
|
||||
|
||||
protected static Object[] varArgThat(Object... expectedArguments) {
|
||||
static Object[] varArgThat(Object... expectedArguments) {
|
||||
return argThat(new VariableArgumentMatcher<>(expectedArguments));
|
||||
}
|
||||
|
||||
private Object[] expectedArguments;
|
||||
private final Object[] expectedArguments;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected VariableArgumentMatcher(Object... expectedArguments) {
|
||||
VariableArgumentMatcher(Object... expectedArguments) {
|
||||
this.expectedArguments = Optional.ofNullable(expectedArguments)
|
||||
.orElseThrow(() -> newIllegalArgumentException("Expected arguments must not be null"));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean matches(T actualArgument) {
|
||||
return asList(this.expectedArguments).containsAll(asList(actualArgument));
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -44,27 +43,26 @@ import org.springframework.data.gemfire.CacheFactoryBean;
|
||||
import org.springframework.data.gemfire.util.ArrayUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PdxDiskStoreAwareBeanFactoryPostProcessor}.
|
||||
* Unit Tests for {@link PdxDiskStoreAwareBeanFactoryPostProcessor}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor
|
||||
* @see org.apache.geode.cache.DiskStore
|
||||
* @see org.apache.geode.cache.Region
|
||||
* @see org.apache.geode.cache.asyncqueue.AsyncEventQueue
|
||||
* @see org.springframework.data.gemfire.config.support.PdxDiskStoreAwareBeanFactoryPostProcessor
|
||||
* @since 1.3.3
|
||||
*/
|
||||
public class PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests {
|
||||
|
||||
protected static boolean isBeanType(BeanDefinition beanDefinition, Class<?> beanType) {
|
||||
return (beanDefinition instanceof AbstractBeanDefinition
|
||||
private static boolean isBeanType(BeanDefinition beanDefinition, Class<?> beanType) {
|
||||
|
||||
return beanDefinition instanceof AbstractBeanDefinition
|
||||
&& ((AbstractBeanDefinition) beanDefinition).hasBeanClass()
|
||||
&& beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass()));
|
||||
&& beanType.isAssignableFrom(((AbstractBeanDefinition) beanDefinition).getBeanClass());
|
||||
}
|
||||
|
||||
protected static String[] toStringArray(Collection<String> collection) {
|
||||
return collection.toArray(new String[collection.size()]);
|
||||
private static String[] toStringArray(Collection<String> collection) {
|
||||
return collection.toArray(new String[0]);
|
||||
}
|
||||
|
||||
protected ConfigurableListableBeanFactory mockBeanFactory(final Map<String, BeanDefinition> beanDefinitions) {
|
||||
@@ -81,7 +79,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests {
|
||||
assertThat(arguments.length).isEqualTo(1);
|
||||
assertThat(arguments[0]).isInstanceOf(Class.class);
|
||||
|
||||
Class beanType = (Class) arguments[0];
|
||||
Class<?> beanType = (Class<?>) arguments[0];
|
||||
|
||||
List<String> beanNames = new ArrayList<>(beanDefinitions.size());
|
||||
|
||||
@@ -114,7 +112,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition();
|
||||
|
||||
if (beanClassObject instanceof Class) {
|
||||
builder.getRawBeanDefinition().setBeanClass((Class) beanClassObject);
|
||||
builder.getRawBeanDefinition().setBeanClass((Class<?>) beanClassObject);
|
||||
}
|
||||
else {
|
||||
builder.getRawBeanDefinition().setBeanClassName(String.valueOf(beanClassObject));
|
||||
@@ -153,7 +151,7 @@ public class PdxDiskStoreAwareBeanFactoryPostProcessorUnitTests {
|
||||
return newBeanDefinitionBuilder(DiskStore.class, dependencies).getBeanDefinition();
|
||||
}
|
||||
|
||||
protected BeanDefinition defineRegion(Class regionClass, String... dependencies) {
|
||||
protected BeanDefinition defineRegion(Class<?> regionClass, String... dependencies) {
|
||||
return newBeanDefinitionBuilder(regionClass, dependencies).getBeanDefinition();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.function.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -32,7 +31,7 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ServerBasedFunctionExecutionBeanDefinitionBuilder}.
|
||||
* Unit Tests for {@link ServerBasedFunctionExecutionBeanDefinitionBuilder}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -43,7 +42,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
public class ServerBasedFunctionExecutionBeanDefinitionBuilderUnitTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getGemfireFunctionOperationsBeanDefinitionBuilder() {
|
||||
|
||||
FunctionExecutionConfiguration mockFunctionExecutionConfiguration =
|
||||
@@ -84,7 +82,6 @@ public class ServerBasedFunctionExecutionBeanDefinitionBuilderUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getGemfireFunctionOperationsBeanDefinitionBuilderWithCache() {
|
||||
|
||||
FunctionExecutionConfiguration mockFunctionExecutionConfiguration =
|
||||
@@ -124,7 +121,6 @@ public class ServerBasedFunctionExecutionBeanDefinitionBuilderUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getGemfireFunctionOperationsBeanDefinitionBuilderWithPool() {
|
||||
|
||||
FunctionExecutionConfiguration mockFunctionExecutionConfiguration =
|
||||
@@ -168,7 +164,6 @@ public class ServerBasedFunctionExecutionBeanDefinitionBuilderUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getGemfireFunctionOperationsBeanDefinitionBuilderWithCacheAndPool() {
|
||||
|
||||
FunctionExecutionConfiguration mockFunctionExecutionConfiguration =
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.repository.query;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -29,7 +28,7 @@ import org.springframework.data.gemfire.mapping.GemfirePersistentEntity;
|
||||
import org.springframework.data.repository.query.parser.PartTree;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link QueryBuilder} class.
|
||||
* Unit Tests for {@link QueryBuilder} class.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene;
|
||||
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -54,10 +53,9 @@ import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.data.gemfire.GemfireUtils;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LuceneIndexFactoryBean}.
|
||||
* Unit Tests for {@link LuceneIndexFactoryBean}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Rule
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.mockito.Mock
|
||||
@@ -65,7 +63,7 @@ import org.springframework.data.gemfire.GemfireUtils;
|
||||
* @see org.mockito.Spy
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.search.lucene.LuceneIndexFactoryBean
|
||||
* @since 1.1.0
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LuceneIndexFactoryBeanUnitTests {
|
||||
@@ -86,7 +84,7 @@ public class LuceneIndexFactoryBeanUnitTests {
|
||||
private LuceneIndexFactory mockLuceneIndexFactory;
|
||||
|
||||
@Mock
|
||||
private LuceneSerializer mockLuceneSerializer;
|
||||
private LuceneSerializer<?> mockLuceneSerializer;
|
||||
|
||||
@Mock
|
||||
private LuceneService mockLuceneService;
|
||||
@@ -242,7 +240,6 @@ public class LuceneIndexFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void destroyIsSuccessful() throws Exception {
|
||||
|
||||
factoryBean.setDestroy(true);
|
||||
@@ -263,7 +260,6 @@ public class LuceneIndexFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void destroyDoesNothingWhenDestroyIsFalse() throws Exception {
|
||||
|
||||
factoryBean.setDestroy(false);
|
||||
@@ -281,7 +277,6 @@ public class LuceneIndexFactoryBeanUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
public void destroyDoesNothingWhenLuceneIndexIsNull() throws Exception {
|
||||
|
||||
factoryBean.setDestroy(true);
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -32,7 +31,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.apache.geode.cache.lucene.LuceneQueryProvider;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link LuceneOperations} interface.
|
||||
* Unit Tests for the {@link LuceneOperations} interface.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -41,7 +40,7 @@ import org.apache.geode.cache.lucene.LuceneQueryProvider;
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.search.lucene.LuceneOperations
|
||||
* @since 1.0.0
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LuceneOperationsUnitTests {
|
||||
@@ -54,6 +53,7 @@ public class LuceneOperationsUnitTests {
|
||||
|
||||
@Test
|
||||
public void stringQueryCallsQueryWithResultLimit() {
|
||||
|
||||
when(mockLuceneOperations.query(anyString(), anyString())).thenCallRealMethod();
|
||||
|
||||
mockLuceneOperations.query("title : Up Shit Creek Without a Paddle", "title");
|
||||
@@ -65,6 +65,7 @@ public class LuceneOperationsUnitTests {
|
||||
|
||||
@Test
|
||||
public void queryProviderQueryCallsQueryWithResultLimit() {
|
||||
|
||||
when(mockLuceneOperations.query(any(LuceneQueryProvider.class))).thenCallRealMethod();
|
||||
|
||||
mockLuceneOperations.query(mockLuceneQueryProvider);
|
||||
@@ -75,6 +76,7 @@ public class LuceneOperationsUnitTests {
|
||||
|
||||
@Test
|
||||
public void stringQueryForKeysCallsQueryForKeysWithResultLimit() {
|
||||
|
||||
when(mockLuceneOperations.queryForKeys(anyString(), anyString())).thenCallRealMethod();
|
||||
|
||||
mockLuceneOperations.queryForKeys("title : Up Shit Creek Without a Paddle", "title");
|
||||
@@ -86,6 +88,7 @@ public class LuceneOperationsUnitTests {
|
||||
|
||||
@Test
|
||||
public void queryProviderQueryForKeysCallsQueryForKeysWithResultLimit() {
|
||||
|
||||
when(mockLuceneOperations.queryForKeys(any(LuceneQueryProvider.class))).thenCallRealMethod();
|
||||
|
||||
mockLuceneOperations.queryForKeys(mockLuceneQueryProvider);
|
||||
@@ -96,6 +99,7 @@ public class LuceneOperationsUnitTests {
|
||||
|
||||
@Test
|
||||
public void stringQueryForValuesCallsQueryForValuesWithResultLimit() {
|
||||
|
||||
when(mockLuceneOperations.queryForValues(anyString(), anyString())).thenCallRealMethod();
|
||||
|
||||
mockLuceneOperations.queryForValues("title : Up Shit Creek Without a Paddle", "title");
|
||||
@@ -107,6 +111,7 @@ public class LuceneOperationsUnitTests {
|
||||
|
||||
@Test
|
||||
public void queryProviderQueryForValuesCallsQueryForValuesWithResultLimit() {
|
||||
|
||||
when(mockLuceneOperations.queryForValues(any(LuceneQueryProvider.class))).thenCallRealMethod();
|
||||
|
||||
mockLuceneOperations.queryForValues(mockLuceneQueryProvider);
|
||||
@@ -115,6 +120,6 @@ public class LuceneOperationsUnitTests {
|
||||
eq(mockLuceneQueryProvider), eq(LuceneOperations.DEFAULT_RESULT_LIMIT));
|
||||
}
|
||||
|
||||
abstract class TestLuceneOperations implements LuceneOperations { }
|
||||
static abstract class TestLuceneOperations implements LuceneOperations { }
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
@@ -49,7 +48,7 @@ import org.apache.geode.cache.lucene.LuceneService;
|
||||
import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LuceneTemplate}.
|
||||
* Unit Tests for {@link LuceneTemplate}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -58,13 +57,13 @@ import org.apache.geode.cache.lucene.PageableLuceneQueryResults;
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.Spy
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.search.lucene.LuceneTemplate
|
||||
* @see org.apache.geode.cache.lucene.LuceneQuery
|
||||
* @see org.apache.geode.cache.lucene.LuceneQueryFactory
|
||||
* @see org.apache.geode.cache.lucene.LuceneQueryProvider
|
||||
* @see org.apache.geode.cache.lucene.LuceneResultStruct
|
||||
* @see org.apache.geode.cache.lucene.LuceneService
|
||||
* @see org.apache.geode.cache.lucene.PageableLuceneQueryResults
|
||||
* @see org.springframework.data.gemfire.search.lucene.LuceneTemplate
|
||||
* @since 1.0.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -95,8 +94,8 @@ public class LuceneTemplateUnitTests {
|
||||
private LuceneTemplate luceneTemplate;
|
||||
|
||||
@Before
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setup() {
|
||||
|
||||
luceneTemplate.setLuceneService(mockLuceneService);
|
||||
|
||||
when(mockLuceneService.createLuceneQueryFactory()).thenReturn(mockLuceneQueryFactory);
|
||||
@@ -105,10 +104,12 @@ public class LuceneTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void stringQueryReturnsList() throws LuceneQueryException {
|
||||
|
||||
when(mockLuceneQueryFactory.create(eq("TestIndex"), eq("/Example"), anyString(), anyString()))
|
||||
.thenReturn(mockLuceneQuery);
|
||||
|
||||
when(mockLuceneQuery.findResults()).thenReturn(asList(mockLuceneResultStructOne, mockLuceneResultStructTwo));
|
||||
|
||||
doReturn("TestIndex").when(luceneTemplate).resolveIndexName();
|
||||
@@ -134,7 +135,7 @@ public class LuceneTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void stringQueryWithPageSizeReturnsPageableResults() throws LuceneQueryException {
|
||||
when(mockLuceneQueryFactory.create(eq("TestIndex"), eq("/Example"), anyString(), anyString()))
|
||||
.thenReturn(mockLuceneQuery);
|
||||
@@ -161,7 +162,7 @@ public class LuceneTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void queryProviderQueryReturnsList() throws LuceneQueryException {
|
||||
when(mockLuceneQueryFactory.create(eq("TestIndex"), eq("/Example"),
|
||||
any(LuceneQueryProvider.class))).thenReturn(mockLuceneQuery);
|
||||
@@ -190,7 +191,7 @@ public class LuceneTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void queryProviderQueryWithPageSizeReturnsPageableResults() throws LuceneQueryException {
|
||||
when(mockLuceneQueryFactory.create(eq("TestIndex"), eq("/Example"),
|
||||
any(LuceneQueryProvider.class))).thenReturn(mockLuceneQuery);
|
||||
@@ -217,7 +218,7 @@ public class LuceneTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void stringQueryForKeysReturnsKeys() throws LuceneQueryException {
|
||||
when(mockLuceneQueryFactory.create(eq("TestIndex"), eq("/Example"), anyString(), anyString()))
|
||||
.thenReturn(mockLuceneQuery);
|
||||
@@ -246,7 +247,7 @@ public class LuceneTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void queryProviderQueryForKeysReturnsKeys() throws LuceneQueryException {
|
||||
when(mockLuceneQueryFactory.create(eq("TestIndex"), eq("/Example"),
|
||||
any(LuceneQueryProvider.class))).thenReturn(mockLuceneQuery);
|
||||
@@ -274,7 +275,7 @@ public class LuceneTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void stringQueryForValuesReturnsValues() throws LuceneQueryException {
|
||||
when(mockLuceneQueryFactory.create(eq("TestIndex"), eq("/Example"), anyString(), anyString()))
|
||||
.thenReturn(mockLuceneQuery);
|
||||
@@ -303,7 +304,7 @@ public class LuceneTemplateUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
public void queryProviderQueryForValuesReturnsValues() throws LuceneQueryException {
|
||||
when(mockLuceneQueryFactory.create(eq("TestIndex"), eq("/Example"),
|
||||
any(LuceneQueryProvider.class))).thenReturn(mockLuceneQuery);
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
@@ -41,7 +40,7 @@ import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ProjectingLuceneAccessor}.
|
||||
* Unit Tests for {@link ProjectingLuceneAccessor}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -51,7 +50,7 @@ import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
* @see org.mockito.Spy
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.search.lucene.ProjectingLuceneAccessor
|
||||
* @since 1.1.0
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProjectingLuceneAccessorUnitTests {
|
||||
@@ -82,6 +81,7 @@ public class ProjectingLuceneAccessorUnitTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
projectingLuceneAccessor = spy(new ProjectingLuceneAccessorSupport() {});
|
||||
|
||||
doReturn(mockCache).when(projectingLuceneAccessor).resolveCache();
|
||||
@@ -92,6 +92,7 @@ public class ProjectingLuceneAccessorUnitTests {
|
||||
|
||||
@Test
|
||||
public void afterPropertiesSetInitializesTheProjectingLuceneAccessorCorrectly() throws Exception {
|
||||
|
||||
doReturn(mockProjectionFactory).when(projectingLuceneAccessor).resolveProjectionFactory();
|
||||
|
||||
projectingLuceneAccessor.afterPropertiesSet();
|
||||
@@ -104,6 +105,7 @@ public class ProjectingLuceneAccessorUnitTests {
|
||||
|
||||
@Test
|
||||
public void projectingLuceneAccessorIsInitializedCorrectly() {
|
||||
|
||||
assertThat(projectingLuceneAccessor.getBeanClassLoader()).isNull();
|
||||
assertThat(projectingLuceneAccessor.getBeanFactory()).isNull();
|
||||
assertThat(projectingLuceneAccessor.getCache()).isNull();
|
||||
@@ -137,6 +139,7 @@ public class ProjectingLuceneAccessorUnitTests {
|
||||
|
||||
@Test
|
||||
public void setThenGetProjectionFactoryIsCorrect() {
|
||||
|
||||
assertThat(projectingLuceneAccessor.getProjectionFactory()).isNull();
|
||||
assertThat(projectingLuceneAccessor.setThenGetProjectionFactory(mockProjectionFactory))
|
||||
.isSameAs(mockProjectionFactory);
|
||||
@@ -145,6 +148,7 @@ public class ProjectingLuceneAccessorUnitTests {
|
||||
|
||||
@Test
|
||||
public void resolveProjectFactoryReturnsProvidedProjectFactory() {
|
||||
|
||||
assertThat(projectingLuceneAccessor.getProjectionFactory()).isNull();
|
||||
|
||||
projectingLuceneAccessor.setProjectionFactory(mockProjectionFactory);
|
||||
@@ -155,6 +159,7 @@ public class ProjectingLuceneAccessorUnitTests {
|
||||
|
||||
@Test
|
||||
public void resolveProjectionFactoryCreatesNewProjectionFactory() {
|
||||
|
||||
assertThat(projectingLuceneAccessor.getProjectionFactory()).isNull();
|
||||
|
||||
ProjectionFactory projectionFactory = projectingLuceneAccessor.resolveProjectionFactory();
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -32,7 +31,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.apache.geode.cache.lucene.LuceneQueryProvider;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ProjectingLuceneOperations}.
|
||||
* Unit Tests for {@link ProjectingLuceneOperations}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -41,7 +40,7 @@ import org.apache.geode.cache.lucene.LuceneQueryProvider;
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.search.lucene.ProjectingLuceneOperations
|
||||
* @since 1.1.0
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProjectingLuceneOperationsUnitTests {
|
||||
@@ -55,6 +54,7 @@ public class ProjectingLuceneOperationsUnitTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void stringQueryCallsQueryWithResultLimit() {
|
||||
|
||||
when(projectingLuceneOperations.query(anyString(), anyString(), any(Class.class))).thenCallRealMethod();
|
||||
|
||||
projectingLuceneOperations.query("title : Up Shit Creek Without A Paddle",
|
||||
@@ -68,6 +68,7 @@ public class ProjectingLuceneOperationsUnitTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void queryProviderQueryCallsQueryWithResultLimit() {
|
||||
|
||||
when(projectingLuceneOperations.query(any(LuceneQueryProvider.class), any(Class.class)))
|
||||
.thenCallRealMethod();
|
||||
|
||||
@@ -79,6 +80,6 @@ public class ProjectingLuceneOperationsUnitTests {
|
||||
|
||||
static class Book {}
|
||||
|
||||
abstract class TestProjectingLuceneOperations implements ProjectingLuceneOperations {
|
||||
}
|
||||
static abstract class TestProjectingLuceneOperations implements ProjectingLuceneOperations { }
|
||||
|
||||
}
|
||||
|
||||
@@ -14,11 +14,10 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Java6Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -50,7 +49,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ProjectingLuceneTemplate}.
|
||||
* Unit Tests for {@link ProjectingLuceneTemplate}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -59,7 +58,8 @@ import lombok.RequiredArgsConstructor;
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.Spy
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @since 1.1.0
|
||||
* @see org.springframework.data.gemfire.search.lucene.ProjectingLuceneTemplate
|
||||
* @since 2.1.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProjectingLuceneTemplateUnitTests {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -23,8 +22,8 @@ import static org.mockito.ArgumentMatchers.isA;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.data.gemfire.search.lucene.support.LucenePage.newLucenePage;
|
||||
|
||||
@@ -52,7 +51,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link LucenePage}.
|
||||
* Unit Tests for {@link LucenePage}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -60,11 +59,11 @@ import lombok.RequiredArgsConstructor;
|
||||
* @see org.mockito.Mock
|
||||
* @see org.mockito.Mockito
|
||||
* @see org.mockito.junit.MockitoJUnitRunner
|
||||
* @see org.springframework.data.gemfire.search.lucene.ProjectingLuceneAccessor
|
||||
* @see org.springframework.data.gemfire.search.lucene.support.LucenePage
|
||||
* @see org.apache.geode.cache.lucene.LuceneResultStruct
|
||||
* @see org.apache.geode.cache.lucene.PageableLuceneQueryResults
|
||||
* @since 1.0.0
|
||||
* @see org.springframework.data.gemfire.search.lucene.ProjectingLuceneAccessor
|
||||
* @see org.springframework.data.gemfire.search.lucene.support.LucenePage
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LucenePageUnitTests {
|
||||
@@ -76,7 +75,7 @@ public class LucenePageUnitTests {
|
||||
private ProjectingLuceneAccessor mockTemplate;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected <K, V> LuceneResultStruct<K, V> mockLuceneResultStruct(K key, V value) {
|
||||
private <K, V> LuceneResultStruct<K, V> mockLuceneResultStruct(K key, V value) {
|
||||
LuceneResultStruct<K, V> mockLuceneResultStruct =
|
||||
mock(LuceneResultStruct.class, String.format("MockLuceneResultStruct$%1$s", key));
|
||||
|
||||
@@ -85,26 +84,26 @@ public class LucenePageUnitTests {
|
||||
return mockLuceneResultStruct;
|
||||
}
|
||||
|
||||
protected List<LuceneResultStruct<Long, String>> mockLuceneResultStructList(List<Person> people) {
|
||||
private List<LuceneResultStruct<Long, String>> mockLuceneResultStructList(List<Person> people) {
|
||||
AtomicLong id = new AtomicLong(0L);
|
||||
|
||||
return people.stream().map(person -> mockLuceneResultStruct(id.incrementAndGet(), person.getName()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
protected List<LuceneResultStruct<Long, String>> prepare(PageableLuceneQueryResults<Long, String> mockQueryResults,
|
||||
private List<LuceneResultStruct<Long, String>> prepare(PageableLuceneQueryResults<Long, String> mockQueryResults,
|
||||
Person... results) {
|
||||
|
||||
return prepare(mockQueryResults, Arrays.asList(results), results.length).get(0);
|
||||
}
|
||||
|
||||
protected List<LuceneResultStruct<Long, String>> prepare(PageableLuceneQueryResults<Long, String> mockQueryResults,
|
||||
private List<LuceneResultStruct<Long, String>> prepare(PageableLuceneQueryResults<Long, String> mockQueryResults,
|
||||
Iterable<Person> results) {
|
||||
|
||||
return prepare(mockQueryResults, results, size(results)).get(0);
|
||||
}
|
||||
|
||||
protected List<List<LuceneResultStruct<Long, String>>> prepare(
|
||||
private List<List<LuceneResultStruct<Long, String>>> prepare(
|
||||
PageableLuceneQueryResults<Long, String> mockQueryResults, Iterable<Person> results, int pageSize) {
|
||||
|
||||
List<List<Person>> pages = paginate(results, pageSize);
|
||||
@@ -112,7 +111,7 @@ public class LucenePageUnitTests {
|
||||
List<List<LuceneResultStruct<Long, String>>> resultStructs =
|
||||
pages.stream().map(this::mockLuceneResultStructList).collect(Collectors.toList());
|
||||
|
||||
Iterator iterator = resultStructs.iterator();
|
||||
Iterator<?> iterator = resultStructs.iterator();
|
||||
|
||||
when(mockQueryResults.hasNext()).thenAnswer(invocation -> iterator.hasNext());
|
||||
when(mockQueryResults.next()).thenAnswer(invocation -> iterator.next());
|
||||
@@ -121,6 +120,7 @@ public class LucenePageUnitTests {
|
||||
}
|
||||
|
||||
private List<List<Person>> paginate(Iterable<Person> people, int pageSize) {
|
||||
|
||||
List<List<Person>> pages = new ArrayList<>();
|
||||
List<Person> page = new ArrayList<>(pageSize);
|
||||
|
||||
@@ -138,7 +138,9 @@ public class LucenePageUnitTests {
|
||||
return pages;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private int size(Iterable<?> iterable) {
|
||||
|
||||
int size = 0;
|
||||
|
||||
for (Object element : iterable) {
|
||||
@@ -150,9 +152,10 @@ public class LucenePageUnitTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
protected ProjectingLuceneAccessor prepare(ProjectingLuceneAccessor mockTemplate) {
|
||||
|
||||
when(mockTemplate.project(isA(List.class), eq(Person.class))).thenAnswer(invocation -> {
|
||||
List<LuceneResultStruct<Long, String>> results = invocation.getArgument(0);
|
||||
assertThat(invocation.<Class>getArgument(1)).isEqualTo(Person.class);
|
||||
assertThat(invocation.<Class<?>>getArgument(1)).isEqualTo(Person.class);
|
||||
return results.stream().map(result -> Person.parse(result.getValue())).collect(Collectors.toList());
|
||||
});
|
||||
|
||||
@@ -160,8 +163,8 @@ public class LucenePageUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void newLucenePageWithNoPreviousPageIsMaterialized() {
|
||||
|
||||
List<Person> people = Collections.singletonList(Person.newPerson("Jon", "Doe"));
|
||||
|
||||
List<LuceneResultStruct<Long, String>> mockResultStructList = prepare(mockQueryResults, people);
|
||||
@@ -188,6 +191,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void newLucenePageWithPreviousPageIsMaterialized() {
|
||||
|
||||
List<Person> expectedContent = Arrays.asList(Person.newPerson("Jon", "Doe"), Person.newPerson("Jane", "Doe"));
|
||||
|
||||
List<List<LuceneResultStruct<Long, String>>> mockResults =
|
||||
@@ -221,6 +225,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void newLucenePageWithNullTemplateThrowsIllegalArgumentException() {
|
||||
|
||||
try {
|
||||
newLucenePage(null, mockQueryResults, 10, Person.class);
|
||||
}
|
||||
@@ -237,6 +242,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void newLucenePageWithNullQueryResultsThrowsIllegalArgumentException() {
|
||||
|
||||
try {
|
||||
newLucenePage(mockTemplate, null, 10, Person.class);
|
||||
}
|
||||
@@ -253,6 +259,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void newLucenePageWithNoContentThrowsIllegalArgumentException() {
|
||||
|
||||
try {
|
||||
when(mockQueryResults.hasNext()).thenReturn(false);
|
||||
newLucenePage(mockTemplate, mockQueryResults, 10, Person.class);
|
||||
@@ -271,6 +278,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void getNextReturnsNextPage() {
|
||||
|
||||
List<Person> expectedContent = Arrays.asList(Person.newPerson("Jon", "Doe"), Person.newPerson("Jane", "Doe"));
|
||||
|
||||
List<List<LuceneResultStruct<Long, String>>> mockResults =
|
||||
@@ -298,6 +306,7 @@ public class LucenePageUnitTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void getNextThrowsIllegalStateExceptionWhenNoMorePages() {
|
||||
|
||||
try {
|
||||
prepare(mockQueryResults, Person.newPerson("Jon", "Doe"));
|
||||
|
||||
@@ -324,8 +333,8 @@ public class LucenePageUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getNumberReturnsOne() {
|
||||
|
||||
prepare(mockQueryResults, Person.newPerson("Jon", "Doe"));
|
||||
|
||||
LucenePage<Person, Long, String> page = newLucenePage(mockTemplate, mockQueryResults, 20, Person.class);
|
||||
@@ -336,8 +345,8 @@ public class LucenePageUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getNumberReturnsTwo() {
|
||||
|
||||
prepare(mockQueryResults, Arrays.asList(Person.newPerson("Jon", "Doe"), Person.newPerson("Jane", "Doe")),
|
||||
1);
|
||||
|
||||
@@ -353,8 +362,8 @@ public class LucenePageUnitTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getNumberReturnsThree() {
|
||||
|
||||
prepare(mockQueryResults, Arrays.asList(Person.newPerson("Jon", "Doe"), Person.newPerson("Jane", "Doe"),
|
||||
Person.newPerson("Pie", "Doe")), 1);
|
||||
|
||||
@@ -375,6 +384,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void getSizeWithNoContentEqualsPageSize() {
|
||||
|
||||
when(mockQueryResults.hasNext()).thenReturn(true);
|
||||
when(mockQueryResults.next()).thenReturn(Collections.emptyList());
|
||||
|
||||
@@ -388,6 +398,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void getSizeWithSingleElementEqualsPageSize() {
|
||||
|
||||
prepare(mockQueryResults, Person.newPerson("Jon", "Doe"));
|
||||
|
||||
LucenePage<Person, Long, String> page =
|
||||
@@ -402,6 +413,7 @@ public class LucenePageUnitTests {
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void getSizeWithMultipleElementsEqualsPageSize() {
|
||||
|
||||
List<Person> mockList = mock(List.class);
|
||||
|
||||
when(mockList.size()).thenReturn(101);
|
||||
@@ -421,6 +433,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void totalElementsEqualsLuceneQueryResultsSize() {
|
||||
|
||||
when(mockQueryResults.hasNext()).thenReturn(true);
|
||||
when(mockQueryResults.next()).thenReturn(Collections.emptyList());
|
||||
when(mockQueryResults.size()).thenReturn(409);
|
||||
@@ -435,6 +448,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void totalPagesIsOneWhenTotalElementsIsLessThanPageSize() {
|
||||
|
||||
when(mockQueryResults.hasNext()).thenReturn(true);
|
||||
when(mockQueryResults.next()).thenReturn(Collections.emptyList());
|
||||
when(mockQueryResults.size()).thenReturn(9);
|
||||
@@ -449,6 +463,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void totalPagesIsOneWhenTotalElementsEqualsPageSize() {
|
||||
|
||||
when(mockQueryResults.hasNext()).thenReturn(true);
|
||||
when(mockQueryResults.next()).thenReturn(Collections.emptyList());
|
||||
when(mockQueryResults.size()).thenReturn(20);
|
||||
@@ -463,6 +478,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void totalPagesIsTwoWhenTotalElementsIsGreaterThanPageSize() {
|
||||
|
||||
when(mockQueryResults.hasNext()).thenReturn(true);
|
||||
when(mockQueryResults.next()).thenReturn(Collections.emptyList());
|
||||
when(mockQueryResults.size()).thenReturn(31);
|
||||
@@ -477,6 +493,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void totalPagesIsFiveWhenTotalElementsIsGreaterThanEqualToPageSize() {
|
||||
|
||||
when(mockQueryResults.hasNext()).thenReturn(true);
|
||||
when(mockQueryResults.next()).thenReturn(Collections.emptyList());
|
||||
when(mockQueryResults.size()).thenReturn(100);
|
||||
@@ -491,6 +508,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void totalPagesIsSixWhenTotalElementsIsGreaterThanPageSize() {
|
||||
|
||||
when(mockQueryResults.hasNext()).thenReturn(true);
|
||||
when(mockQueryResults.next()).thenReturn(Collections.emptyList());
|
||||
when(mockQueryResults.size()).thenReturn(101);
|
||||
@@ -505,6 +523,7 @@ public class LucenePageUnitTests {
|
||||
|
||||
@Test
|
||||
public void mapIsSuccessful() {
|
||||
|
||||
List<Person> expectedContent = Arrays.asList(Person.newPerson("Jon", "Doe"), Person.newPerson("Jane", "Doe"));
|
||||
|
||||
prepare(mockQueryResults, expectedContent);
|
||||
@@ -526,6 +545,7 @@ public class LucenePageUnitTests {
|
||||
@Data
|
||||
@RequiredArgsConstructor(staticName = "newPerson")
|
||||
static class Person {
|
||||
|
||||
@NonNull String firstName;
|
||||
@NonNull String lastName;
|
||||
|
||||
@@ -542,6 +562,7 @@ public class LucenePageUnitTests {
|
||||
@Data
|
||||
@RequiredArgsConstructor(staticName = "newUser")
|
||||
static class User {
|
||||
|
||||
@NonNull String name;
|
||||
|
||||
static User from(Person person) {
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.search.lucene.support;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
@@ -23,8 +22,8 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.data.gemfire.search.lucene.support.PdxInstanceMethodInterceptor.newPdxInstanceMethodInterceptor;
|
||||
|
||||
@@ -45,7 +44,7 @@ import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link PdxInstanceMethodInterceptor}.
|
||||
* Unit Tests for {@link PdxInstanceMethodInterceptor}.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
@@ -69,12 +68,13 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
private WritablePdxInstance mockNewSource;
|
||||
|
||||
@SafeVarargs
|
||||
protected static <T> T[] asArray(T... array) {
|
||||
private static <T> T[] asArray(T... array) {
|
||||
return array;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newPdxInstanceMethodInterceptorWithValidObjectSourceIsSuccessful() {
|
||||
|
||||
PdxInstanceMethodInterceptor methodInterceptor = newPdxInstanceMethodInterceptor((Object) mockSource);
|
||||
|
||||
assertThat(methodInterceptor).isNotNull();
|
||||
@@ -83,6 +83,7 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void newPdxInstanceMethodInterceptorWithInvalidObjectSourceThrowsIllegalArgumentException() {
|
||||
|
||||
try {
|
||||
newPdxInstanceMethodInterceptor(new Object());
|
||||
}
|
||||
@@ -97,6 +98,7 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
|
||||
@Test
|
||||
public void newPdxInstanceMethodInterceptorWithPdxInstanceIsSuccessful() {
|
||||
|
||||
PdxInstanceMethodInterceptor methodInterceptor = newPdxInstanceMethodInterceptor(mockSource);
|
||||
|
||||
assertThat(methodInterceptor).isNotNull();
|
||||
@@ -105,6 +107,7 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void constructPdxInstanceMethodInterceptorWithNullThrowsIllegalArgumentException() {
|
||||
|
||||
try {
|
||||
new PdxInstanceMethodInterceptor(null);
|
||||
}
|
||||
@@ -118,6 +121,7 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
|
||||
@Test
|
||||
public void invokeObjectMethodIsHandled() throws Throwable {
|
||||
|
||||
Person jonDoe = Person.newPerson("Jon", "Doe");
|
||||
Method toString = jonDoe.getClass().getMethod("toString");
|
||||
|
||||
@@ -133,6 +137,7 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
|
||||
@Test
|
||||
public void invokeGetterOnSourceIsHandled() throws Throwable {
|
||||
|
||||
Person jonDoe = Person.newPerson("Jon", "Doe");
|
||||
Method getFirstName = jonDoe.getClass().getMethod("getFirstName");
|
||||
|
||||
@@ -150,6 +155,7 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
|
||||
@Test
|
||||
public void invokeSetterOnSourceIsHandled() throws Throwable {
|
||||
|
||||
Person jonDoe = Person.newPerson("Jon", "Doe");
|
||||
Method setLastName = jonDoe.getClass().getMethod("setLastName", String.class);
|
||||
|
||||
@@ -172,6 +178,7 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void invokeThrowsIllegalStateExceptionWhenPdxInstanceDoesNotHaveField() throws Throwable {
|
||||
|
||||
Method getGender = Person.class.getMethod("getGender");
|
||||
|
||||
when(mockMethodInvocation.getMethod()).thenReturn(getGender);
|
||||
@@ -222,6 +229,7 @@ public class PdxInstanceMethodInterceptorUnitTests {
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void invokeThrowsIllegalArgumentExceptionWhenPdxInstanceHasNoWriter() throws Throwable {
|
||||
|
||||
Method setGender = Person.class.getMethod("setGender", Gender.class);
|
||||
|
||||
when(mockMethodInvocation.getMethod()).thenReturn(setGender);
|
||||
|
||||
Reference in New Issue
Block a user