Skip to content

Commit 3dbdbd9

Browse files
committed
Accept Double and Boolean in MapOutput #2429
1 parent dd0715e commit 3dbdbd9

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

src/main/java/io/lettuce/core/output/MapOutput.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ public void set(long integer) {
6868
key = null;
6969
}
7070

71+
@Override
72+
public void set(double number) {
73+
74+
if (key == null) {
75+
key = (K) Double.valueOf(number);
76+
return;
77+
}
78+
79+
V value = (V) Double.valueOf(number);
80+
output.put(key, value);
81+
key = null;
82+
}
83+
84+
@Override
85+
public void set(boolean flag) {
86+
87+
if (key == null) {
88+
key = (K) Boolean.valueOf(flag);
89+
return;
90+
}
91+
92+
V value = (V) Boolean.valueOf(flag);
93+
output.put(key, value);
94+
key = null;
95+
}
96+
7197
@Override
7298
public void multi(int count) {
7399

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2023 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+
* https://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 io.lettuce.core.output;
17+
18+
import static org.assertj.core.api.Assertions.*;
19+
20+
import java.nio.ByteBuffer;
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import io.lettuce.core.codec.StringCodec;
25+
26+
/**
27+
* Unit tests for {@link MapOutput}.
28+
*
29+
* @author Mark Paluch
30+
*/
31+
class MapOutputUnitTests {
32+
33+
@Test
34+
void shouldAcceptValue() {
35+
36+
MapOutput<String, String> sut = new MapOutput<>(StringCodec.UTF8);
37+
sut.multi(2);
38+
sut.set(ByteBuffer.wrap("hello".getBytes()));
39+
sut.set(ByteBuffer.wrap("world".getBytes()));
40+
41+
assertThat(sut.get()).containsEntry("hello", "world");
42+
}
43+
44+
@Test
45+
void shouldAcceptBoolean() {
46+
47+
MapOutput<String, Object> sut = new MapOutput(StringCodec.UTF8);
48+
sut.multi(2);
49+
sut.set(ByteBuffer.wrap("hello".getBytes()));
50+
sut.set(true);
51+
52+
assertThat(sut.get()).containsEntry("hello", true);
53+
}
54+
55+
@Test
56+
void shouldAcceptDouble() {
57+
58+
MapOutput<String, Object> sut = new MapOutput(StringCodec.UTF8);
59+
sut.multi(2);
60+
sut.set(ByteBuffer.wrap("hello".getBytes()));
61+
sut.set(1.2);
62+
63+
assertThat(sut.get()).containsEntry("hello", 1.2);
64+
}
65+
66+
@Test
67+
void shouldAcceptInteger() {
68+
69+
MapOutput<String, Object> sut = new MapOutput(StringCodec.UTF8);
70+
sut.multi(2);
71+
sut.set(ByteBuffer.wrap("hello".getBytes()));
72+
sut.set(1L);
73+
74+
assertThat(sut.get()).containsEntry("hello", 1L);
75+
}
76+
77+
}

0 commit comments

Comments
 (0)