|
| 1 | +/** |
| 2 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * <p>Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 5 | + * |
| 6 | + * <p>Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file |
| 7 | + * except in compliance with the License. A copy of the License is located at |
| 8 | + * |
| 9 | + * <p>http://aws.amazon.com/apache2.0 |
| 10 | + * |
| 11 | + * <p>or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 13 | + * specific language governing permissions and limitations under the License. |
| 14 | + */ |
| 15 | +package com.uber.cadence.internal.worker; |
| 16 | + |
| 17 | +import static org.junit.Assert.assertEquals; |
| 18 | +import static org.junit.Assert.assertThrows; |
| 19 | + |
| 20 | +import org.junit.Before; |
| 21 | +import org.junit.Test; |
| 22 | + |
| 23 | +public class CircularLongBufferTest { |
| 24 | + |
| 25 | + private CircularLongBuffer buffer; |
| 26 | + private CircularLongBuffer buffer2; |
| 27 | + |
| 28 | + @Before |
| 29 | + public void setUp() { |
| 30 | + // Initialize a buffer with specific values for testing |
| 31 | + buffer = new CircularLongBuffer(new long[] {1, 2, 3, 4, 5}); |
| 32 | + buffer2 = new CircularLongBuffer(new long[] {}); |
| 33 | + } |
| 34 | + |
| 35 | + @Test |
| 36 | + public void testCopyZeroLength() { |
| 37 | + // Copy with zero length should result in an empty buffer |
| 38 | + CircularLongBuffer copyBuffer = buffer.copy(2, 0); |
| 39 | + assertEquals(0, copyBuffer.size()); |
| 40 | + } |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testEdgeCase() { |
| 44 | + // Copy with zero length should result in an empty buffer |
| 45 | + CircularLongBuffer copyBuffer = buffer.copy(100, 3); |
| 46 | + assertEquals(3, copyBuffer.size()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + public void testValuesZero() { |
| 51 | + // Copy with zero length should result in an empty buffer |
| 52 | + assertThrows(IllegalStateException.class, () -> buffer2.copy(2, 3)); |
| 53 | + } |
| 54 | +} |
0 commit comments