From 5164d169af57d4b2edea50a91a4618df148e130b Mon Sep 17 00:00:00 2001 From: Tim Li <47233368+timl3136@users.noreply.github.com> Date: Tue, 12 Nov 2024 09:28:19 -0800 Subject: [PATCH] Add unit tests CircularLongBuffer (#960) --- .../worker/CircularLongBufferTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/test/java/com/uber/cadence/internal/worker/CircularLongBufferTest.java diff --git a/src/test/java/com/uber/cadence/internal/worker/CircularLongBufferTest.java b/src/test/java/com/uber/cadence/internal/worker/CircularLongBufferTest.java new file mode 100644 index 00000000..1217f0a3 --- /dev/null +++ b/src/test/java/com/uber/cadence/internal/worker/CircularLongBufferTest.java @@ -0,0 +1,54 @@ +/** + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + *

Modifications copyright (C) 2017 Uber Technologies, Inc. + * + *

Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file + * except in compliance with the License. A copy of the License is located at + * + *

http://aws.amazon.com/apache2.0 + * + *

or in the "license" file accompanying this file. This file 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 com.uber.cadence.internal.worker; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThrows; + +import org.junit.Before; +import org.junit.Test; + +public class CircularLongBufferTest { + + private CircularLongBuffer buffer; + private CircularLongBuffer buffer2; + + @Before + public void setUp() { + // Initialize a buffer with specific values for testing + buffer = new CircularLongBuffer(new long[] {1, 2, 3, 4, 5}); + buffer2 = new CircularLongBuffer(new long[] {}); + } + + @Test + public void testCopyZeroLength() { + // Copy with zero length should result in an empty buffer + CircularLongBuffer copyBuffer = buffer.copy(2, 0); + assertEquals(0, copyBuffer.size()); + } + + @Test + public void testEdgeCase() { + // Copy with zero length should result in an empty buffer + CircularLongBuffer copyBuffer = buffer.copy(100, 3); + assertEquals(3, copyBuffer.size()); + } + + @Test + public void testValuesZero() { + // Copy with zero length should result in an empty buffer + assertThrows(IllegalStateException.class, () -> buffer2.copy(2, 3)); + } +}