PageRenderTime 24ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/hazelcast/src/test/java/com/hazelcast/util/SimpleBoundedQueueTest.java

https://bitbucket.org/gabral6_gmailcom/hazelcast
Java | 103 lines | 69 code | 13 blank | 21 comment | 4 complexity | 52ce1beb1965057ece5372ae7c556eef MD5 | raw file
  1/*
  2 * Copyright (c) 2008-2013, Hazelcast, Inc. All Rights Reserved.
  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
 17package com.hazelcast.util;
 18
 19import org.junit.After;
 20import org.junit.Test;
 21import org.junit.runner.RunWith;
 22
 23import static junit.framework.Assert.*;
 24
 25@RunWith(com.hazelcast.util.RandomBlockJUnit4ClassRunner.class)
 26public class SimpleBoundedQueueTest {
 27
 28    private SimpleBoundedQueue<String> queue = new SimpleBoundedQueue<String>(10);
 29
 30    @After
 31    public void clear() {
 32        queue.clear();
 33    }
 34
 35    @Test
 36    public void testAdd() {
 37        queue.add("hello");
 38        assertEquals("hello", queue.poll());
 39    }
 40
 41    @Test
 42    public void testSize() {
 43        queue.add("hello");
 44        assertEquals(1, queue.size());
 45        queue.add("world");
 46        assertEquals(2, queue.size());
 47    }
 48
 49    @Test
 50    public void testOffer() {
 51        queue.offer("hello");
 52        queue.offer("world");
 53        assertEquals("hello", queue.poll());
 54        assertEquals("world", queue.poll());
 55    }
 56
 57    @Test
 58    public void testPeek() {
 59        queue.offer("hello");
 60        queue.add("world");
 61        assertEquals("hello", queue.peek());
 62    }
 63
 64    @Test
 65    public void testPoll() {
 66        queue.offer("hello");
 67        queue.offer("hello");
 68        assertEquals("hello", queue.poll());
 69        assertEquals("hello", queue.poll());
 70    }
 71
 72    @Test
 73    public void testCapacity() {
 74        queue.clear();
 75        assertEquals(0, queue.size());
 76        for (int i = 0; i < 10; i++) {
 77            assertTrue(queue.offer(String.valueOf(i)));
 78            assertEquals(i + 1, queue.size());
 79        }
 80        for (int i = 0; i < 5; i++) {
 81            assertFalse(queue.offer(String.valueOf(i)));
 82            assertEquals(10, queue.size());
 83        }
 84        for (int i = 0; i < 5; i++) {
 85            assertEquals(String.valueOf(i), queue.poll());
 86            assertEquals(10 - i - 1, queue.size());
 87        }
 88        for (int i = 0; i < 5; i++) {
 89            assertTrue(queue.offer(String.valueOf(i)));
 90        }
 91        assertEquals(10, queue.size());
 92    }
 93
 94    @Test
 95    public void testIterator() {
 96        // Unsupported
 97        /*queue.offer("hello");
 98        queue.offer("hello");
 99        for(String message: queue){
100            assertEquals("hello", message);
101        }*/
102    }
103}