Fix source code warnings.

This commit is contained in:
John Blum
2020-11-04 10:07:40 -08:00
parent d6451d9395
commit 495abe59e8
7 changed files with 78 additions and 82 deletions

View File

@@ -429,7 +429,6 @@ public class AbstractGemFireOperationsSessionRepositoryTests {
assertThat(this.sessionRepository.getApplicationEventPublisher()).isSameAs(mockApplicationEventPublisher);
}
@SuppressWarnings("all")
@Test(expected = IllegalArgumentException.class)
public void setApplicationEventPublisherToNull() {
@@ -2252,7 +2251,6 @@ public class AbstractGemFireOperationsSessionRepositoryTests {
assertThat(session.getAttributes()).isEmpty();
}
@SuppressWarnings("all")
@Test(expected = IllegalArgumentException.class)
public void copyNullThrowsIllegalArgumentException() {
@@ -2371,7 +2369,6 @@ public class AbstractGemFireOperationsSessionRepositoryTests {
verify(mockSession, never()).getAttribute(anyString());
}
@SuppressWarnings("all")
@Test(expected = IllegalArgumentException.class)
public void fromNullSessionThrowsIllegalArgumentException() {

View File

@@ -134,6 +134,7 @@ public class GemFireOperationsSessionRepositoryTests {
verify(this.mockTemplate, times(1)).getRegion();
}
@SuppressWarnings("rawtypes")
private GemFireSession newNonDirtyGemFireSession() {
GemFireSession session = GemFireSession.create();
@@ -186,7 +187,7 @@ public class GemFireOperationsSessionRepositoryTests {
assertThat(session.getCreationTime()).isAfterOrEqualTo(beforeCreationTime);
assertThat(session.getCreationTime()).isBeforeOrEqualTo(Instant.now());
assertThat(session.isExpired()).isFalse();
assertThat(((GemFireSession) session).getIsDirtyPredicate()).isEqualTo(EqualsDirtyPredicate.INSTANCE);
assertThat(((GemFireSession<?>) session).getIsDirtyPredicate()).isEqualTo(EqualsDirtyPredicate.INSTANCE);
assertThat(session.getLastAccessedTime()).isEqualTo(session.getCreationTime());
assertThat(session.getMaxInactiveInterval()).isEqualTo(Duration.ofSeconds(MAX_INACTIVE_INTERVAL_IN_SECONDS));
}
@@ -544,10 +545,9 @@ public class GemFireOperationsSessionRepositoryTests {
}
@Test
@SuppressWarnings("unchecked")
public void saveWillNotStoreNonDirtyGemFireSessions() {
GemFireSession session = newNonDirtyGemFireSession();
GemFireSession<?> session = newNonDirtyGemFireSession();
assertThat(session).isNotNull();
assertThat(session.hasDelta()).isFalse();

View File

@@ -77,22 +77,26 @@ import org.springframework.util.ReflectionUtils;
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.ExpirationAttributes
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.Region
* @see org.apache.geode.cache.RegionAttributes
* @see org.apache.geode.cache.RegionShortcut
* @see org.apache.geode.cache.ExpirationAttributes
* @see org.apache.geode.cache.RegionAttributes
* @see org.apache.geode.cache.client.ClientCache
* @see org.apache.geode.cache.client.ClientRegionShortcut
* @see org.springframework.beans.factory.config.ConfigurableListableBeanFactory
* @see org.springframework.context.ApplicationContext
* @see org.springframework.context.ConfigurableApplicationContext
* @see org.springframework.core.env.ConfigurableEnvironment
* @see org.springframework.core.env.Environment
* @see org.springframework.core.env.PropertySource
* @see org.springframework.core.type.AnnotationMetadata
* @see org.springframework.data.gemfire.GemfireOperations
* @see org.springframework.data.gemfire.GemfireTemplate
* @see org.springframework.session.Session
* @see org.springframework.session.data.gemfire.GemFireOperationsSessionRepository
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionCacheTypeAwareRegionFactoryBean
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SpringSessionGemFireConfigurer
* @since 1.1.0
*/
public class GemFireHttpSessionConfigurationUnitTests {
@@ -127,7 +131,7 @@ public class GemFireHttpSessionConfigurationUnitTests {
if (field == null) {
throw new NoSuchFieldException(String.format("Field with name [%1$s] was not found in class [%2$s]",
fieldName, type));
fieldName, type.getName()));
}
return field;
@@ -155,8 +159,8 @@ public class GemFireHttpSessionConfigurationUnitTests {
this.gemfireConfiguration.setBeanClassLoader(Thread.currentThread().getContextClassLoader());
assertThat(this.gemfireConfiguration.getBeanClassLoader()).isEqualTo(
Thread.currentThread().getContextClassLoader());
assertThat(this.gemfireConfiguration.getBeanClassLoader())
.isEqualTo(Thread.currentThread().getContextClassLoader());
this.gemfireConfiguration.setBeanClassLoader(null);
@@ -166,18 +170,18 @@ public class GemFireHttpSessionConfigurationUnitTests {
@Test
public void setAndGetClientRegionShortcut() {
assertThat(this.gemfireConfiguration.getClientRegionShortcut()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_CLIENT_REGION_SHORTCUT);
assertThat(this.gemfireConfiguration.getClientRegionShortcut())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_CLIENT_REGION_SHORTCUT);
this.gemfireConfiguration.setClientRegionShortcut(ClientRegionShortcut.CACHING_PROXY);
assertThat(this.gemfireConfiguration.getClientRegionShortcut()).isEqualTo(
ClientRegionShortcut.CACHING_PROXY);
assertThat(this.gemfireConfiguration.getClientRegionShortcut())
.isEqualTo(ClientRegionShortcut.CACHING_PROXY);
this.gemfireConfiguration.setClientRegionShortcut(null);
assertThat(this.gemfireConfiguration.getClientRegionShortcut()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_CLIENT_REGION_SHORTCUT);
assertThat(this.gemfireConfiguration.getClientRegionShortcut())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_CLIENT_REGION_SHORTCUT);
}
@Test
@@ -239,8 +243,8 @@ public class GemFireHttpSessionConfigurationUnitTests {
@Test
public void setAndGetMaxInactiveIntervalInSeconds() {
assertThat(this.gemfireConfiguration.getMaxInactiveIntervalInSeconds()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS);
assertThat(this.gemfireConfiguration.getMaxInactiveIntervalInSeconds())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_MAX_INACTIVE_INTERVAL_IN_SECONDS);
this.gemfireConfiguration.setMaxInactiveIntervalInSeconds(300);
@@ -262,8 +266,8 @@ public class GemFireHttpSessionConfigurationUnitTests {
@Test
public void setAndGetPoolName() {
assertThat(this.gemfireConfiguration.getPoolName()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_POOL_NAME);
assertThat(this.gemfireConfiguration.getPoolName())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_POOL_NAME);
this.gemfireConfiguration.setPoolName("TestPoolName");
@@ -271,35 +275,35 @@ public class GemFireHttpSessionConfigurationUnitTests {
this.gemfireConfiguration.setPoolName(" ");
assertThat(this.gemfireConfiguration.getPoolName()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_POOL_NAME);
assertThat(this.gemfireConfiguration.getPoolName())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_POOL_NAME);
this.gemfireConfiguration.setPoolName("");
assertThat(this.gemfireConfiguration.getPoolName()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_POOL_NAME);
assertThat(this.gemfireConfiguration.getPoolName())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_POOL_NAME);
this.gemfireConfiguration.setPoolName(null);
assertThat(this.gemfireConfiguration.getPoolName()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_POOL_NAME);
assertThat(this.gemfireConfiguration.getPoolName())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_POOL_NAME);
}
@Test
public void setAndGetServerRegionShortcut() {
assertThat(this.gemfireConfiguration.getServerRegionShortcut()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_SERVER_REGION_SHORTCUT);
assertThat(this.gemfireConfiguration.getServerRegionShortcut())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_SERVER_REGION_SHORTCUT);
this.gemfireConfiguration.setServerRegionShortcut(RegionShortcut.REPLICATE_PERSISTENT);
assertThat(this.gemfireConfiguration.getServerRegionShortcut()).isEqualTo(
RegionShortcut.REPLICATE_PERSISTENT);
assertThat(this.gemfireConfiguration.getServerRegionShortcut())
.isEqualTo(RegionShortcut.REPLICATE_PERSISTENT);
this.gemfireConfiguration.setServerRegionShortcut(null);
assertThat(this.gemfireConfiguration.getServerRegionShortcut()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_SERVER_REGION_SHORTCUT);
assertThat(this.gemfireConfiguration.getServerRegionShortcut())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_SERVER_REGION_SHORTCUT);
}
@Test
@@ -338,8 +342,8 @@ public class GemFireHttpSessionConfigurationUnitTests {
@Test
public void setAndGetSessionRegionName() {
assertThat(this.gemfireConfiguration.getSessionRegionName()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME);
assertThat(this.gemfireConfiguration.getSessionRegionName())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME);
this.gemfireConfiguration.setSessionRegionName("test");
@@ -347,18 +351,18 @@ public class GemFireHttpSessionConfigurationUnitTests {
this.gemfireConfiguration.setSessionRegionName(" ");
assertThat(this.gemfireConfiguration.getSessionRegionName()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME);
assertThat(this.gemfireConfiguration.getSessionRegionName())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME);
this.gemfireConfiguration.setSessionRegionName("");
assertThat(this.gemfireConfiguration.getSessionRegionName()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME);
assertThat(this.gemfireConfiguration.getSessionRegionName())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME);
this.gemfireConfiguration.setSessionRegionName(null);
assertThat(this.gemfireConfiguration.getSessionRegionName()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME);
assertThat(this.gemfireConfiguration.getSessionRegionName())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_SESSION_REGION_NAME);
}
@Test
@@ -407,12 +411,14 @@ public class GemFireHttpSessionConfigurationUnitTests {
assertThat(this.gemfireConfiguration.getSessionSerializerBeanName())
.isEqualTo(GemFireHttpSessionConfiguration.SESSION_PDX_SERIALIZER_BEAN_NAME);
assertThat(this.gemfireConfiguration.isUsingDataSerialization()).isFalse();
this.gemfireConfiguration.setSessionSerializerBeanName(null);
assertThat(this.gemfireConfiguration.getSessionSerializerBeanName())
.isEqualTo(GemFireHttpSessionConfiguration.SESSION_PDX_SERIALIZER_BEAN_NAME);
assertThat(this.gemfireConfiguration.isUsingDataSerialization()).isFalse();
}
@@ -694,8 +700,8 @@ public class GemFireHttpSessionConfigurationUnitTests {
verify(mockApplicationContext, times(1)).getBeanFactory();
verify(mockBeanFactory, times(1)).registerAlias(eq("testSessionSerializer"),
eq(GemFireHttpSessionConfiguration.SESSION_SERIALIZER_BEAN_ALIAS));
verify(mockBeanFactory, times(1))
.registerAlias(eq("testSessionSerializer"), eq(GemFireHttpSessionConfiguration.SESSION_SERIALIZER_BEAN_ALIAS));
}
@Test

View File

@@ -16,32 +16,31 @@
package org.springframework.session.data.gemfire.config.annotation.web.http.support;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import org.junit.Before;
import org.junit.Test;
import org.apache.geode.cache.query.Index;
import org.springframework.data.gemfire.util.ArrayUtils;
import org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration;
/**
* Test suite of test cases testing the contract and functionality
* of the {@link SessionAttributesIndexFactoryBean} class.
* Unit Tests for {@link SessionAttributesIndexFactoryBean}.
*
* @author John Blum
* @since 1.3.0
* @see org.junit.Test
* @see org.mockito.Mockito
* @see org.apache.geode.cache.query.Index
* @see org.springframework.session.data.gemfire.config.annotation.web.http.GemFireHttpSessionConfiguration
* @see org.springframework.session.data.gemfire.config.annotation.web.http.support.SessionAttributesIndexFactoryBean
* @since 1.3.0
*/
public class SessionAttributesIndexFactoryBeanTests {
@SuppressWarnings("unchecked")
static <T> T[] toArray(T... array) {
return array;
}
private SessionAttributesIndexFactoryBean indexFactoryBean;
@Before
@@ -52,15 +51,11 @@ public class SessionAttributesIndexFactoryBeanTests {
@Test
public void indexIsNotInitializedWhenNoIndexableSessionAttributesAreConfigured() throws Exception {
final Index mockIndex = mock(Index.class);
Index mockIndex = mock(Index.class);
SessionAttributesIndexFactoryBean indexFactoryBean = new SessionAttributesIndexFactoryBean() {
SessionAttributesIndexFactoryBean indexFactoryBean = spy(new SessionAttributesIndexFactoryBean());
@Override
protected Index newIndex() {
return mockIndex;
}
};
doReturn(mockIndex).when(indexFactoryBean).newIndex();
indexFactoryBean.afterPropertiesSet();
@@ -71,17 +66,13 @@ public class SessionAttributesIndexFactoryBeanTests {
@Test
public void initializesIndexWhenIndexableSessionAttributesAreConfigured() throws Exception {
final Index mockIndex = mock(Index.class);
Index mockIndex = mock(Index.class);
SessionAttributesIndexFactoryBean indexFactoryBean = new SessionAttributesIndexFactoryBean() {
SessionAttributesIndexFactoryBean indexFactoryBean = spy(new SessionAttributesIndexFactoryBean());
@Override
protected Index newIndex() {
return mockIndex;
}
};
doReturn(mockIndex).when(indexFactoryBean).newIndex();
indexFactoryBean.setIndexableSessionAttributes(toArray("one", "two"));
indexFactoryBean.setIndexableSessionAttributes(ArrayUtils.asArray("one", "two"));
indexFactoryBean.afterPropertiesSet();
assertThat(indexFactoryBean.getObject()).isEqualTo(mockIndex);
@@ -95,34 +86,36 @@ public class SessionAttributesIndexFactoryBeanTests {
@Test
public void setAndGetIndexableSessionAttributes() {
assertThat(this.indexFactoryBean.getIndexableSessionAttributes()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
assertThat(this.indexFactoryBean.getIndexableSessionAttributes())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
assertThat(this.indexFactoryBean.getIndexableSessionAttributesAsGemFireIndexExpression()).isEqualTo("*");
this.indexFactoryBean.setIndexableSessionAttributes(toArray("one", "two", "three"));
this.indexFactoryBean.setIndexableSessionAttributes(ArrayUtils.asArray("one", "two", "three"));
assertThat(this.indexFactoryBean.getIndexableSessionAttributes()).isEqualTo(
toArray("one", "two", "three"));
assertThat(this.indexFactoryBean.getIndexableSessionAttributes())
.isEqualTo(ArrayUtils.asArray("one", "two", "three"));
assertThat(this.indexFactoryBean.getIndexableSessionAttributesAsGemFireIndexExpression()).isEqualTo(
"'one', 'two', 'three'");
assertThat(this.indexFactoryBean.getIndexableSessionAttributesAsGemFireIndexExpression())
.isEqualTo("'one', 'two', 'three'");
this.indexFactoryBean.setIndexableSessionAttributes(toArray("one"));
this.indexFactoryBean.setIndexableSessionAttributes(ArrayUtils.asArray("one"));
assertThat(this.indexFactoryBean.getIndexableSessionAttributes()).isEqualTo(toArray("one"));
assertThat(this.indexFactoryBean.getIndexableSessionAttributes()).isEqualTo(ArrayUtils.asArray("one"));
assertThat(this.indexFactoryBean.getIndexableSessionAttributesAsGemFireIndexExpression()).isEqualTo("'one'");
this.indexFactoryBean.setIndexableSessionAttributes(null);
assertThat(this.indexFactoryBean.getIndexableSessionAttributes()).isEqualTo(
GemFireHttpSessionConfiguration.DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
assertThat(this.indexFactoryBean.getIndexableSessionAttributes())
.isEqualTo(GemFireHttpSessionConfiguration.DEFAULT_INDEXABLE_SESSION_ATTRIBUTES);
assertThat(this.indexFactoryBean.getIndexableSessionAttributesAsGemFireIndexExpression()).isEqualTo("*");
}
@Test
public void setAndGetRegionName() {
assertThat(this.indexFactoryBean.getRegionName()).isNull();
this.indexFactoryBean.setRegionName("Example");

View File

@@ -175,6 +175,7 @@ public class SessionCacheTypeAwareRegionFactoryBeanTests {
public void setAndGetGemFireCache() {
Cache mockCache = mock(Cache.class);
ClientCache mockClientCache = mock(ClientCache.class);
this.regionFactoryBean.setCache(mockCache);

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.data.gemfire.expiration;
import static org.assertj.core.api.Assertions.assertThat;
@@ -28,7 +27,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
/**
* Unit tests for {@link SessionExpirationPolicy}.
* Unit Tests for {@link SessionExpirationPolicy}.
*
* @author John Blum
* @see org.junit.Test

View File

@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.session.data.gemfire.serialization;
import static org.assertj.core.api.Assertions.assertThat;
@@ -30,7 +29,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
/**
* Unit tests for the {@link SessionSerializer} interface.
* Unit Tests for the {@link SessionSerializer} interface.
*
* @author John Blum
* @see org.junit.Test
@@ -43,6 +42,7 @@ import org.mockito.junit.MockitoJUnitRunner;
public class SessionSerializerTests {
@Mock
@SuppressWarnings("rawtypes")
private SessionSerializer sessionSerializer;
@Test