diff options
author | bvosburgh | 2007-09-01 00:16:34 +0000 |
---|---|---|
committer | bvosburgh | 2007-09-01 00:16:34 +0000 |
commit | 428159b00fa3b24516470491d21fffe7cf460351 (patch) | |
tree | ea7281299bf7865c03bce98aa10e92b9fd5946f9 /jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleStackTests.java | |
parent | 600fc0c48e2c2c59480c5843eb0285e053018286 (diff) | |
download | webtools.dali-428159b00fa3b24516470491d21fffe7cf460351.tar.gz webtools.dali-428159b00fa3b24516470491d21fffe7cf460351.tar.xz webtools.dali-428159b00fa3b24516470491d21fffe7cf460351.zip |
[201159] model rework - added "node" support
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleStackTests.java')
-rw-r--r-- | jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleStackTests.java | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleStackTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleStackTests.java new file mode 100644 index 0000000000..f229797565 --- /dev/null +++ b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/SimpleStackTests.java @@ -0,0 +1,142 @@ +/******************************************************************************* + * Copyright (c) 2007 Oracle. All rights reserved. + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0, which accompanies this distribution + * and is available at http://www.eclipse.org/legal/epl-v10.html. + * + * Contributors: + * Oracle - initial API and implementation + ******************************************************************************/ +package org.eclipse.jpt.utility.tests.internal; + +import java.util.EmptyStackException; + +import org.eclipse.jpt.utility.internal.SimpleStack; +import org.eclipse.jpt.utility.internal.Stack; + +import junit.framework.TestCase; + +public class SimpleStackTests extends TestCase { + + public SimpleStackTests(String name) { + super(name); + } + + public void testIsEmpty() { + Stack<String> stack = new SimpleStack<String>(); + assertTrue(stack.isEmpty()); + stack.push("first"); + assertFalse(stack.isEmpty()); + stack.push("second"); + assertFalse(stack.isEmpty()); + stack.pop(); + assertFalse(stack.isEmpty()); + stack.pop(); + assertTrue(stack.isEmpty()); + } + + public void testPushAndPop() { + Stack<String> stack = new SimpleStack<String>(); + String first = "first"; + String second = "second"; + + stack.push(first); + stack.push(second); + assertEquals(second, stack.pop()); + assertEquals(first, stack.pop()); + } + + public void testPushAndPeek() { + Stack<String> stack = new SimpleStack<String>(); + String first = "first"; + String second = "second"; + + stack.push(first); + stack.push(second); + assertEquals(second, stack.peek()); + assertEquals(second, stack.peek()); + assertEquals(second, stack.pop()); + assertEquals(first, stack.peek()); + assertEquals(first, stack.peek()); + assertEquals(first, stack.pop()); + } + + public void testEmptyStackExceptionPeek() { + Stack<String> stack = new SimpleStack<String>(); + String first = "first"; + String second = "second"; + + stack.push(first); + stack.push(second); + assertEquals(second, stack.peek()); + assertEquals(second, stack.pop()); + assertEquals(first, stack.peek()); + assertEquals(first, stack.pop()); + + boolean exCaught = false; + try { + stack.peek(); + } catch (EmptyStackException ex) { + exCaught = true; + } + assertTrue(exCaught); + } + + public void testEmptyStackExceptionPop() { + Stack<String> stack = new SimpleStack<String>(); + String first = "first"; + String second = "second"; + + stack.push(first); + stack.push(second); + assertEquals(second, stack.peek()); + assertEquals(second, stack.pop()); + assertEquals(first, stack.peek()); + assertEquals(first, stack.pop()); + + boolean exCaught = false; + try { + stack.pop(); + } catch (EmptyStackException ex) { + exCaught = true; + } + assertTrue(exCaught); + } + + public void testClone() { + SimpleStack<String> stack = new SimpleStack<String>(); + stack.push("first"); + stack.push("second"); + stack.push("third"); + + this.verifyClone(stack, stack.clone()); + } + + public void testSerialization() throws Exception { + SimpleStack<String> stack = new SimpleStack<String>(); + stack.push("first"); + stack.push("second"); + stack.push("third"); + + this.verifyClone(stack, TestTools.serialize(stack)); + } + + private void verifyClone(Stack<String> original, Stack<String> clone) { + assertNotSame(original, clone); + assertEquals(original.peek(), clone.peek()); + assertEquals(original.pop(), clone.pop()); + assertEquals(original.peek(), clone.peek()); + assertEquals(original.pop(), clone.pop()); + assertEquals(original.isEmpty(), clone.isEmpty()); + assertEquals(original.peek(), clone.peek()); + assertEquals(original.pop(), clone.pop()); + assertTrue(original.isEmpty()); + assertEquals(original.isEmpty(), clone.isEmpty()); + + original.push("fourth"); + assertFalse(original.isEmpty()); + // clone should still be empty + assertTrue(clone.isEmpty()); + } + +} |