Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3e9d610

Browse files
committed
DATAREDIS-803 - Polishing.
Remove DefaultRedisMapEntry as it's no longer required. Simplify test to unit test to reduce test scope and test run time. Original pull request: #326.
1 parent 8ed4703 commit 3e9d610

File tree

3 files changed

+60
-57
lines changed

3 files changed

+60
-57
lines changed

‎src/main/java/org/springframework/data/redis/support/collections/DefaultRedisMap.java‎

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import java.util.Collection;
1919
import java.util.Collections;
2020
import java.util.Date;
21-
import java.util.Iterator;
22-
import java.util.LinkedHashSet;
2321
import java.util.Map;
2422
import java.util.Set;
2523
import java.util.concurrent.TimeUnit;
@@ -44,34 +42,6 @@ public class DefaultRedisMap<K, V> implements RedisMap<K, V> {
4442

4543
private final BoundHashOperations<String, K, V> hashOps;
4644

47-
private class DefaultRedisMapEntry implements Map.Entry<K, V> {
48-
49-
private final K key;
50-
private @Nullable final V value;
51-
52-
public DefaultRedisMapEntry(K key, @Nullable V value) {
53-
54-
this.key = key;
55-
this.value = value;
56-
}
57-
58-
@Override
59-
public K getKey() {
60-
return key;
61-
}
62-
63-
@Override
64-
@Nullable
65-
public V getValue() {
66-
return value;
67-
}
68-
69-
@Override
70-
public V setValue(@Nullable V value) {
71-
throw new UnsupportedOperationException();
72-
}
73-
}
74-
7545
/**
7646
* Constructs a new {@link DefaultRedisMap} instance.
7747
*
@@ -280,10 +250,7 @@ public int hashCode() {
280250
@Override
281251
public String toString() {
282252

283-
StringBuilder sb = new StringBuilder();
284-
sb.append("RedisStore for key:");
285-
sb.append(getKey());
286-
return sb.toString();
253+
return "RedisStore for key:" + getKey();
287254
}
288255

289256
/*

‎src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java‎

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.util.ArrayList;
2626
import java.util.Collection;
2727
import java.util.Collections;
28-
import java.util.HashMap;
2928
import java.util.LinkedHashMap;
3029
import java.util.LinkedHashSet;
3130
import java.util.Map;
@@ -84,7 +83,7 @@ public RedisConnectionFactory getConnectionFactory() {
8483
abstract RedisMap<K, V> createMap();
8584

8685
@Before
87-
public void setUp() throwsException{
86+
public void setUp() {
8887
map = createMap();
8988
}
9089

@@ -398,27 +397,6 @@ public void testEntrySet() {
398397
assertThat(values, not(hasItem(v2)));
399398
}
400399

401-
@Test // DATAREDIS-803
402-
@IfProfileValue(name = "runLongTests", value = "true")
403-
public void testBigEntrySet() {
404-
405-
Set<Entry<K, V>> entries = map.entrySet();
406-
assertTrue(entries.isEmpty());
407-
408-
for (int j = 0; j < 2; j++) {
409-
Map<K, V> m = new HashMap<>();
410-
for (int i = 0; i < 1024 * 1024 / 2 - 1; i++) {
411-
m.put(getKey(), getValue());
412-
}
413-
map.putAll(m);
414-
}
415-
map.put(getKey(), getValue());
416-
417-
entries = map.entrySet();
418-
419-
assertEquals(1024 * 1024 - 1, entries.size());
420-
}
421-
422400
@Test
423401
public void testPutIfAbsent() {
424402

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.redis.support.collections;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
import static org.mockito.Mockito.*;
20+
21+
import java.util.Collections;
22+
import java.util.Map.Entry;
23+
import java.util.Set;
24+
25+
import org.junit.Before;
26+
import org.junit.Test;
27+
import org.junit.runner.RunWith;
28+
import org.mockito.Mock;
29+
import org.mockito.junit.MockitoJUnitRunner;
30+
import org.springframework.data.redis.core.BoundHashOperations;
31+
32+
/**
33+
* Unit tests for {@link DefaultRedisMap}.
34+
*
35+
* @author Mark Paluch
36+
*/
37+
@RunWith(MockitoJUnitRunner.class)
38+
public class DefaultRedisMapUnitUnitTests {
39+
40+
@Mock BoundHashOperations<String, String, String> operationsMock;
41+
42+
DefaultRedisMap<String, String> map;
43+
44+
@Before
45+
public void before() {
46+
map = new DefaultRedisMap<>(operationsMock);
47+
}
48+
49+
@Test // DATAREDIS-803
50+
public void shouldGetEntrySet() {
51+
52+
when(operationsMock.entries()).thenReturn(Collections.singletonMap("foo", "bar"));
53+
54+
Set<Entry<String, String>> result = map.entrySet();
55+
56+
assertThat(result).hasSize(1);
57+
}
58+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /