DATAREDIS-1172 - Polishing.

Suppress rawtypes/unchecked warnings. Use static imports for mockito.

Original pull request: #542.
This commit is contained in:
Mark Paluch
2020-07-15 11:57:54 +02:00
parent 6152dfa3c7
commit fbccc05d5b
2 changed files with 11 additions and 11 deletions

View File

@@ -328,7 +328,7 @@ public interface StreamReceiver<K, V extends Record<K, ?>> {
* @param pair must not be {@literal null}.
* @return {@code this} {@link StreamReceiverOptionsBuilder}.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> StreamReceiverOptionsBuilder<T, MapRecord<T, T, T>> serializer(SerializationPair<T> pair) {
Assert.notNull(pair, "SerializationPair must not be null");
@@ -345,7 +345,7 @@ public interface StreamReceiver<K, V extends Record<K, ?>> {
* @param serializationContext must not be {@literal null}.
* @return {@code this} {@link StreamReceiverOptionsBuilder}.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> StreamReceiverOptionsBuilder<T, MapRecord<T, T, T>> serializer(
RedisSerializationContext<T, ?> serializationContext) {
@@ -364,7 +364,7 @@ public interface StreamReceiver<K, V extends Record<K, ?>> {
* @param pair must not be {@literal null}.
* @return {@code this} {@link StreamReceiverOptionsBuilder}.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public <NK, NV extends Record<NK, ?>> StreamReceiverOptionsBuilder<NK, NV> keySerializer(
SerializationPair<NK> pair) {
@@ -380,7 +380,7 @@ public interface StreamReceiver<K, V extends Record<K, ?>> {
* @param pair must not be {@literal null}.
* @return {@code this} {@link StreamReceiverOptionsBuilder}.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public <HK, HV> StreamReceiverOptionsBuilder<K, MapRecord<K, HK, HV>> hashKeySerializer(
SerializationPair<HK> pair) {
@@ -396,7 +396,7 @@ public interface StreamReceiver<K, V extends Record<K, ?>> {
* @param pair must not be {@literal null}.
* @return {@code this} {@link StreamReceiverOptionsBuilder}.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public <HK, HV> StreamReceiverOptionsBuilder<K, MapRecord<K, HK, HV>> hashValueSerializer(
SerializationPair<HV> pair) {
@@ -412,7 +412,7 @@ public interface StreamReceiver<K, V extends Record<K, ?>> {
* @param targetType must not be {@literal null}.
* @return {@code this} {@link StreamReceiverOptionsBuilder}.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public <NV> StreamReceiverOptionsBuilder<K, ObjectRecord<K, NV>> targetType(Class<NV> targetType) {
Assert.notNull(targetType, "Target type must not be null");
@@ -435,7 +435,7 @@ public interface StreamReceiver<K, V extends Record<K, ?>> {
* @param hashMapper must not be {@literal null}.
* @return {@code this} {@link StreamReceiverOptionsBuilder}.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public <NV> StreamReceiverOptionsBuilder<K, ObjectRecord<K, NV>> objectMapper(HashMapper<NV, ?, ?> hashMapper) {
Assert.notNull(hashMapper, "HashMapper must not be null");

View File

@@ -18,6 +18,7 @@ package org.springframework.data.redis.stream;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -32,7 +33,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.RedisVersionUtils;
@@ -175,8 +176,8 @@ public class StreamReceiverIntegrationTests {
@Test // DATAREDIS-1172
public void shouldReceiveCustomHashValueRecords() {
SerializationPair<Integer> serializationPair = Mockito.mock(SerializationPair.class);
Mockito.when(serializationPair.read(any(ByteBuffer.class))).thenReturn(345920);
SerializationPair<Integer> serializationPair = mock(SerializationPair.class);
when(serializationPair.read(any(ByteBuffer.class))).thenReturn(345920);
StreamReceiverOptions<String, MapRecord<String, String, Integer>> receiverOptions = StreamReceiverOptions.builder()
.<String, Integer>hashValueSerializer(serializationPair).build();
@@ -227,7 +228,6 @@ public class StreamReceiverIntegrationTests {
}).consumeNextWith(it -> {
assertThat(it.getStream()).isEqualTo("my-stream");
// assertThat(it.getValue()).containsEntry("key", "value3");
}) //
.thenCancel() //
.verify(Duration.ofSeconds(5));