diff --git a/samza-api/src/test/java/org/apache/samza/serializers/TestByteBufferSerde.java b/samza-api/src/test/java/org/apache/samza/serializers/TestByteBufferSerde.java new file mode 100644 index 0000000000..b907921314 --- /dev/null +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestByteBufferSerde.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.samza.serializers; + +import java.nio.ByteBuffer; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + + +public class TestByteBufferSerde { + @Test + public void testSerde() { + ByteBufferSerde serde = new ByteBufferSerde(); + assertNull(serde.toBytes(null)); + assertNull(serde.fromBytes(null)); + + byte[] bytes = "A lazy way of creating a byte array".getBytes(); + ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); + byteBuffer.mark(); + assertArrayEquals(bytes, serde.toBytes(byteBuffer)); + byteBuffer.reset(); + assertEquals(byteBuffer, serde.fromBytes(bytes)); + } + + @Test + public void testSerializationPreservesInput() { + ByteBufferSerde serde = new ByteBufferSerde(); + byte[] bytes = "A lazy way of creating a byte array".getBytes(); + ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); + byteBuffer.get(); // advance position by 1 + serde.toBytes(byteBuffer); + + assertEquals(byteBuffer.capacity(), byteBuffer.limit()); + assertEquals(1, byteBuffer.position()); + } +} diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestByteSerde.scala b/samza-api/src/test/java/org/apache/samza/serializers/TestByteSerde.java similarity index 61% rename from samza-api/src/test/scala/org.apache.samza.serializers/TestByteSerde.scala rename to samza-api/src/test/java/org/apache/samza/serializers/TestByteSerde.java index f605762c72..10baff4ba2 100644 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestByteSerde.scala +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestByteSerde.java @@ -16,23 +16,23 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.samza.serializers; -package org.apache.samza.serializers +import org.junit.Test; -import java.util.Arrays +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertNull; -import org.junit.Assert._ -import org.junit.Test -class TestByteSerde { +public class TestByteSerde { @Test - def testByteSerde { - val serde = new ByteSerde - assertNull(serde.toBytes(null)) - assertNull(serde.fromBytes(null)) + public void testByteSerde() { + ByteSerde serde = new ByteSerde(); + assertNull(serde.toBytes(null)); + assertNull(serde.fromBytes(null)); - val testBytes = "A lazy way of creating a byte array".getBytes() - assertArrayEquals(serde.toBytes(testBytes), testBytes) - assertArrayEquals(serde.fromBytes(testBytes), testBytes) + byte[] testBytes = "A lazy way of creating a byte array".getBytes(); + assertArrayEquals(testBytes, serde.toBytes(testBytes)); + assertArrayEquals(testBytes, serde.fromBytes(testBytes)); } } diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestIntegerSerde.scala b/samza-api/src/test/java/org/apache/samza/serializers/TestDoubleSerde.java similarity index 57% rename from samza-api/src/test/scala/org.apache.samza.serializers/TestIntegerSerde.scala rename to samza-api/src/test/java/org/apache/samza/serializers/TestDoubleSerde.java index a3e7e1fcd5..a47f865eba 100644 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestIntegerSerde.scala +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestDoubleSerde.java @@ -16,22 +16,25 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.samza.serializers; -package org.apache.samza.serializers +import org.junit.Test; -import org.junit.Assert._ -import org.junit.Test +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -class TestIntegerSerde { + +public class TestDoubleSerde { @Test - def testIntegerSerde { - val serde = new IntegerSerde - assertEquals(null, serde.toBytes(null)) - assertEquals(null, serde.fromBytes(null)) + public void testDoubleSerde() { + DoubleSerde serde = new DoubleSerde(); + assertNull(serde.toBytes(null)); + assertNull(serde.fromBytes(null)); - val fooBar = 37 - val fooBarBytes = serde.toBytes(fooBar) - assertArrayEquals(Array[Byte](0, 0, 0, 37), fooBarBytes) - assertEquals(fooBar, serde.fromBytes(fooBarBytes)) + Double fooBar = 9.156013e-002; + byte[] fooBarBytes = serde.toBytes(fooBar); + assertArrayEquals(new byte[]{63, -73, 112, 124, 19, -9, -82, -93}, fooBarBytes); + assertEquals(fooBar, serde.fromBytes(fooBarBytes)); } } diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestLongSerde.scala b/samza-api/src/test/java/org/apache/samza/serializers/TestIntegerSerde.java similarity index 58% rename from samza-api/src/test/scala/org.apache.samza.serializers/TestLongSerde.scala rename to samza-api/src/test/java/org/apache/samza/serializers/TestIntegerSerde.java index 77a7498bd6..f47412cc84 100644 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestLongSerde.scala +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestIntegerSerde.java @@ -16,25 +16,25 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.samza.serializers; -package org.apache.samza.serializers +import org.junit.Test; -import java.util.Arrays +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -import org.junit.Assert._ -import org.junit.Test -class TestLongSerde { +public class TestIntegerSerde { @Test - def testLongSerde { - val serde = new LongSerde - assertEquals(null, serde.toBytes(null)) - assertEquals(null, serde.fromBytes(null)) + public void testIntegerSerde() { + IntegerSerde serde = new IntegerSerde(); + assertNull(serde.toBytes(null)); + assertNull(serde.fromBytes(null)); - val fooBar = 1234123412341234L - val fooBarBytes = serde.toBytes(fooBar) - fooBarBytes.foreach(System.err.println) - assertArrayEquals(Array[Byte](0, 4, 98, 109, -65, -102, 1, -14), fooBarBytes) - assertEquals(fooBar, serde.fromBytes(fooBarBytes)) + Integer fooBar = 37; + byte[] fooBarBytes = serde.toBytes(fooBar); + assertArrayEquals(new byte[]{0, 0, 0, 37}, fooBarBytes); + assertEquals(fooBar, serde.fromBytes(fooBarBytes)); } } diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestJsonSerdeV2.scala b/samza-api/src/test/java/org/apache/samza/serializers/TestJsonSerdeV2.java similarity index 50% rename from samza-api/src/test/scala/org.apache.samza.serializers/TestJsonSerdeV2.scala rename to samza-api/src/test/java/org/apache/samza/serializers/TestJsonSerdeV2.java index f5202c8940..2c087d208f 100644 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestJsonSerdeV2.scala +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestJsonSerdeV2.java @@ -16,30 +16,32 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.samza.serializers; -package org.apache.samza.serializers +import java.util.HashMap; +import java.util.Map; +import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; -import org.junit.Assert._ -import org.junit.Test -import scala.collection.JavaConverters._ - - -class TestJsonSerdeV2 { +public class TestJsonSerdeV2 { @Test - def testJsonSerdeV2ShouldWork { - val serde = new JsonSerdeV2[java.util.HashMap[String, Object]] - val obj = new java.util.HashMap[String, Object](Map[String, Object]("hi" -> "bye", "why" -> new java.lang.Integer(2)).asJava) - val bytes = serde.toBytes(obj) - assertEquals(obj, serde.fromBytes(bytes)) - val serdeHashMapEntry = new JsonSerdeV2[java.util.Map.Entry[String, Object]] - obj.entrySet().asScala.foreach(entry => { - try { - val entryBytes = serdeHashMapEntry.toBytes(entry) - } catch { - case e: Exception => fail("HashMap Entry serialization failed!") - } - }) + public void testJsonSerdeV2ShouldWork() { + JsonSerdeV2> serde = new JsonSerdeV2<>(); + HashMap obj = new HashMap<>(); + obj.put("hi", "bye"); + obj.put("why", 2); + byte[] bytes = serde.toBytes(obj); + assertEquals(obj, serde.fromBytes(bytes)); + JsonSerdeV2> serdeHashMapEntry = new JsonSerdeV2<>(); + obj.entrySet().forEach(entry -> { + try { + serdeHashMapEntry.toBytes(entry); + } catch (Exception e) { + fail("HashMap Entry serialization failed!"); + } + }); } } diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestDoubleSerde.scala b/samza-api/src/test/java/org/apache/samza/serializers/TestLongSerde.java similarity index 58% rename from samza-api/src/test/scala/org.apache.samza.serializers/TestDoubleSerde.scala rename to samza-api/src/test/java/org/apache/samza/serializers/TestLongSerde.java index 60241b5557..addb9b6cc1 100644 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestDoubleSerde.scala +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestLongSerde.java @@ -16,25 +16,25 @@ * specific language governing permissions and limitations * under the License. */ +package org.apache.samza.serializers; -package org.apache.samza.serializers +import org.junit.Test; -import java.util.Arrays +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; -import org.junit.Assert._ -import org.junit.Test -class TestDoubleSerde { +public class TestLongSerde { @Test - def testDoubleSerde { - val serde = new DoubleSerde - assertEquals(null, serde.toBytes(null)) - assertEquals(null, serde.fromBytes(null)) + public void testLongSerde() { + LongSerde serde = new LongSerde(); + assertNull(serde.toBytes(null)); + assertNull(serde.fromBytes(null)); - val fooBar = 9.156013e-002 - val fooBarBytes = serde.toBytes(fooBar) - fooBarBytes.foreach(System.err.println) - assertArrayEquals(Array[Byte](63, -73, 112, 124, 19, -9, -82, -93), fooBarBytes) - assertEquals(fooBar, serde.fromBytes(fooBarBytes)) + Long fooBar = 1234123412341234L; + byte[] fooBarBytes = serde.toBytes(fooBar); + assertArrayEquals(new byte[]{0, 4, 98, 109, -65, -102, 1, -14}, fooBarBytes); + assertEquals(fooBar, serde.fromBytes(fooBarBytes)); } } diff --git a/samza-api/src/test/java/org/apache/samza/serializers/TestSerializableSerde.java b/samza-api/src/test/java/org/apache/samza/serializers/TestSerializableSerde.java new file mode 100644 index 0000000000..ab44dd505e --- /dev/null +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestSerializableSerde.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.samza.serializers; + +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + + +public class TestSerializableSerde { + @Test + public void testSerializableSerde() { + SerializableSerde serde = new SerializableSerde<>(); + assertNull(serde.toBytes(null)); + assertNull(serde.fromBytes(null)); + + String obj = "String is serializable"; + + // Serialized string is prefix + string itself + List expectedBytesList = new ArrayList<>( + Arrays.asList((byte) 0xAC, (byte) 0xED, (byte) 0x00, (byte) 0x05, (byte) 0x74, (byte) 0x00, (byte) 0x16)); + for (byte b : obj.getBytes(StandardCharsets.UTF_8)) { + expectedBytesList.add(b); + } + // need to unbox to primitive byte + byte[] expected = new byte[expectedBytesList.size()]; + for (int i = 0; i < expectedBytesList.size(); i++) { + expected[i] = expectedBytesList.get(i); + } + + byte[] bytes = serde.toBytes(obj); + + assertArrayEquals(expected, bytes); + + String objRoundTrip = serde.fromBytes(bytes); + assertEquals(obj, objRoundTrip); + } +} diff --git a/samza-api/src/test/java/org/apache/samza/serializers/TestStringSerde.java b/samza-api/src/test/java/org/apache/samza/serializers/TestStringSerde.java new file mode 100644 index 0000000000..23d44f7597 --- /dev/null +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestStringSerde.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.samza.serializers; + +import java.nio.charset.StandardCharsets; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + + +public class TestStringSerde { + @Test + public void testStringSerde() { + StringSerde serde = new StringSerde("UTF-8"); + assertNull(serde.toBytes(null)); + assertNull(serde.fromBytes(null)); + + String fooBar = "foo bar"; + byte[] fooBarBytes = serde.toBytes(fooBar); + assertArrayEquals(fooBar.getBytes(StandardCharsets.UTF_8), fooBarBytes); + assertEquals(fooBar, serde.fromBytes(fooBarBytes)); + } +} diff --git a/samza-api/src/test/java/org/apache/samza/serializers/TestUUIDSerde.java b/samza-api/src/test/java/org/apache/samza/serializers/TestUUIDSerde.java new file mode 100644 index 0000000000..f1b4d4be40 --- /dev/null +++ b/samza-api/src/test/java/org/apache/samza/serializers/TestUUIDSerde.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.samza.serializers; + +import java.nio.BufferUnderflowException; +import java.util.UUID; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + + +public class TestUUIDSerde { + private UUIDSerde serde = new UUIDSerde(); + + @Test + public void testUUIDSerde() { + UUID uuid = new UUID(13, 42); + byte[] bytes = serde.toBytes(uuid); + assertArrayEquals(new byte[]{0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 42}, bytes); + assertEquals(uuid, serde.fromBytes(bytes)); + } + + @Test + public void testToBytesWhenNull() { + assertNull(serde.toBytes(null)); + } + + @Test + public void testFromBytesWhenNull() { + assertNull(serde.fromBytes(null)); + } + + @Test(expected = BufferUnderflowException.class) + public void testFromBytesWhenInvalid() { + serde.fromBytes(new byte[]{0}); + } +} diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestByteBufferSerde.scala b/samza-api/src/test/scala/org.apache.samza.serializers/TestByteBufferSerde.scala deleted file mode 100644 index eddfb0ad8e..0000000000 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestByteBufferSerde.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.samza.serializers - -import java.util.Arrays -import org.junit.Assert._ -import org.junit.Test -import java.nio.ByteBuffer - -class TestByteBufferSerde { - @Test - def testSerde { - val serde = new ByteBufferSerde - assertNull(serde.toBytes(null)) - assertNull(serde.fromBytes(null)) - - val bytes = "A lazy way of creating a byte array".getBytes() - val byteBuffer = ByteBuffer.wrap(bytes) - byteBuffer.mark() - assertArrayEquals(serde.toBytes(byteBuffer), bytes) - byteBuffer.reset() - assertEquals(serde.fromBytes(bytes), byteBuffer) - } - - @Test - def testSerializationPreservesInput { - val serde = new ByteBufferSerde - val bytes = "A lazy way of creating a byte array".getBytes() - val byteBuffer = ByteBuffer.wrap(bytes) - byteBuffer.get() // advance position by 1 - serde.toBytes(byteBuffer) - - assertEquals(byteBuffer.capacity(), byteBuffer.limit()) - assertEquals(1, byteBuffer.position()) - } -} \ No newline at end of file diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestSerializableSerde.scala b/samza-api/src/test/scala/org.apache.samza.serializers/TestSerializableSerde.scala deleted file mode 100644 index 8e899d07ec..0000000000 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestSerializableSerde.scala +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.samza.serializers - -import org.junit.Assert._ -import org.junit.Test - -class TestSerializableSerde { - @Test - def testSerializableSerde { - val serde = new SerializableSerde[String] - assertNull(serde.toBytes(null)) - assertNull(serde.fromBytes(null)) - - val obj = "String is serializable" - - // Serialized string is prefix + string itself - val prefix = Array(0xAC, 0xED, 0x00, 0x05, 0x74, 0x00, 0x16).map(_.toByte) - val expected = (prefix ++ obj.getBytes("UTF-8")) - - val bytes = serde.toBytes(obj) - - assertArrayEquals(expected, bytes) - - val objRoundTrip:String = serde.fromBytes(bytes) - assertEquals(obj, objRoundTrip) - } -} diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestStringSerde.scala b/samza-api/src/test/scala/org.apache.samza.serializers/TestStringSerde.scala deleted file mode 100644 index a1e8e882cd..0000000000 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestStringSerde.scala +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.samza.serializers - -import org.junit.Assert._ -import org.junit.Test - -class TestStringSerde { - @Test - def testStringSerde { - val serde = new StringSerde("UTF-8") - assertEquals(null, serde.toBytes(null)) - assertEquals(null, serde.fromBytes(null)) - - val fooBar = "foo bar" - val fooBarBytes = serde.toBytes(fooBar) - assertArrayEquals(fooBar.getBytes("UTF-8"), fooBarBytes) - assertEquals(fooBar, serde.fromBytes(fooBarBytes)) - } -} diff --git a/samza-api/src/test/scala/org.apache.samza.serializers/TestUUIDSerde.scala b/samza-api/src/test/scala/org.apache.samza.serializers/TestUUIDSerde.scala deleted file mode 100644 index 04ddcdbe30..0000000000 --- a/samza-api/src/test/scala/org.apache.samza.serializers/TestUUIDSerde.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.samza.serializers - -import java.nio.BufferUnderflowException -import java.util.UUID - -import org.junit.Assert._ -import org.junit.Test - -class TestUUIDSerde { - private val serde = new UUIDSerde - - @Test - def testUUIDSerde { - val uuid = new UUID(13, 42) - val bytes = serde.toBytes(uuid) - assertArrayEquals(Array[Byte](0, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 42), bytes) - assertEquals(uuid, serde.fromBytes(bytes)) - } - - @Test - def testToBytesWhenNull { - assertEquals(null, serde.toBytes(null)) - } - - @Test - def testFromBytesWhenNull { - assertEquals(null, serde.fromBytes(null)) - } - - @Test(expected = classOf[BufferUnderflowException]) - def testFromBytesWhenInvalid { - assertEquals(null, serde.fromBytes(Array[Byte](0))) - } -}