|
| 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