|
| 1 | +// |
| 2 | +// MessagePack for Java |
| 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.msgpack.core |
| 17 | + |
| 18 | +import java.io.ByteArrayOutputStream |
| 19 | +import java.util.Arrays |
| 20 | +import org.msgpack.core.MessagePack.{UnpackerConfig, PackerConfig} |
| 21 | +import org.msgpack.core.buffer.OutputStreamBufferOutput |
| 22 | +import org.msgpack.value.Value |
| 23 | +import org.msgpack.value.ValueFactory._ |
| 24 | + |
| 25 | +/** |
| 26 | + * |
| 27 | + */ |
| 28 | +class MessageBufferPackerTest extends MessagePackSpec { |
| 29 | + "MessageBufferPacker" should { |
| 30 | + "be equivalent to ByteArrayOutputStream" in { |
| 31 | + val packer1 = MessagePack.newDefaultBufferPacker() |
| 32 | + packer1.packValue(newMap(Array[Value]( |
| 33 | + newString("a"), newInteger(1), |
| 34 | + newString("b"), newString("s")))) |
| 35 | + |
| 36 | + val stream = new ByteArrayOutputStream() |
| 37 | + val packer2 = MessagePack.newDefaultPacker(stream) |
| 38 | + packer2.packValue(newMap(Array[Value]( |
| 39 | + newString("a"), newInteger(1), |
| 40 | + newString("b"), newString("s")))) |
| 41 | + packer2.flush() |
| 42 | + |
| 43 | + Arrays.equals(packer1.toByteArray(), stream.toByteArray()) shouldBe true |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments