Java Code Examples for java.util.concurrent.ConcurrentLinkedDeque#push()

The following examples show how to use java.util.concurrent.ConcurrentLinkedDeque#push() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * push(null) throws NPE
 */
public void testPushNull() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    try {
        q.push(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 2
Source File: ConcurrentLinkedDequeTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * peekFirst() returns element inserted with push
 */
public void testPush() {
    ConcurrentLinkedDeque q = populatedDeque(3);
    q.pollLast();
    q.push(four);
    assertSame(four, q.peekFirst());
}
 
Example 3
Source File: ConcurrentLinkedDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * push(null) throws NPE
 */
public void testPushNull() {
    ConcurrentLinkedDeque q = new ConcurrentLinkedDeque();
    try {
        q.push(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
Example 4
Source File: ConcurrentLinkedDequeTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * peekFirst() returns element inserted with push
 */
public void testPush() {
    ConcurrentLinkedDeque q = populatedDeque(3);
    q.pollLast();
    q.push(four);
    assertSame(four, q.peekFirst());
}
 
Example 5
Source File: StackUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenConcurrentLinkedDeque_whenPushPopPeek_thenWorkRight() {
    ConcurrentLinkedDeque<String> namesStack = new ConcurrentLinkedDeque<>();

    namesStack.push("Bill Gates");
    namesStack.push("Elon Musk");

    Assert.assertEquals("Elon Musk", namesStack.peek());
    Assert.assertEquals("Elon Musk", namesStack.pop());
    Assert.assertEquals("Bill Gates", namesStack.pop());

    Assert.assertEquals(0, namesStack.size());
}