Updated Branches: refs/heads/master 8215e9d1b -> ae5d15345
Convert TestNG to Spock Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/ae5d1534 Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/ae5d1534 Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/ae5d1534 Branch: refs/heads/master Commit: ae5d153451f0750fb9085d265317e87a9716ed22 Parents: cf48bba Author: Howard M. Lewis Ship <[email protected]> Authored: Fri Jun 1 18:29:35 2012 -0700 Committer: Howard M. Lewis Ship <[email protected]> Committed: Fri Jun 1 18:29:35 2012 -0700 ---------------------------------------------------------------------- .../org/apache/tapestry5/util/StackSpec.groovy | 113 ++++++++++++++ .../org/apache/tapestry5/ioc/util/StackTest.java | 118 --------------- 2 files changed, 113 insertions(+), 118 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ae5d1534/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StackSpec.groovy ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StackSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StackSpec.groovy new file mode 100644 index 0000000..d5f17b8 --- /dev/null +++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/util/StackSpec.groovy @@ -0,0 +1,113 @@ +package org.apache.tapestry5.util + +import org.apache.tapestry5.ioc.util.Stack +import spock.lang.Specification + +class StackSpec extends Specification { + + def stack = new Stack() + + def "peek in empty stack is failure"() { + + when: + + stack.peek() + + then: + + IllegalStateException e = thrown() + + e.message == "Stack is empty." + } + + def "pop in empty stack is failure"() { + + when: + + stack.pop() + + then: + + IllegalStateException e = thrown() + + e.message == "Stack is empty." + } + + def "simple stack operations"() { + + def fred = "fred" + def barney = "barney" + + expect: + + stack.empty + + when: + + stack.push fred + + then: + + stack.peek().is(fred) + !stack.empty + + when: + + stack.push barney + + then: + + stack.peek().is(barney) + + stack.toString() == "Stack[barney, fred]" + + stack.depth == 2 + + stack.snapshot.equals([fred, barney]) + + when: + + def popped = stack.pop() + + then: + + popped.is barney + stack.peek().is(fred) + !stack.empty + + when: + + popped = stack.pop() + + then: + + popped.is fred + stack.empty + } + + def "force the expansion of the inner data"() { + + def limit = 1000 + + when: + + limit.times { stack.push it } + + then: + + limit.downto(1) { stack.pop() == it - 1} + } + + def "clear the stack"() { + + 10.times { stack.push it } + + when: + + stack.clear() + + then: + + stack.empty + } +} http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ae5d1534/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/StackTest.java ---------------------------------------------------------------------- diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/StackTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/StackTest.java deleted file mode 100644 index 24dee47..0000000 --- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/util/StackTest.java +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2007, 2008 The Apache Software Foundation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License 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 org.apache.tapestry5.ioc.util; - -import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newStack; -import org.apache.tapestry5.ioc.test.TestBase; -import org.testng.annotations.Test; - -public class StackTest extends TestBase -{ - @Test - public void peek_in_empty_stack_is_failure() - { - Stack<Integer> stack = newStack(); - - try - { - stack.peek(); - unreachable(); - } - catch (IllegalStateException ex) - { - assertEquals(ex.getMessage(), "Stack is empty."); - } - } - - @Test - public void pop_in_empty_stack_is_failure() - { - Stack<Integer> stack = newStack(); - - try - { - stack.pop(); - unreachable(); - } - catch (IllegalStateException ex) - { - assertEquals(ex.getMessage(), "Stack is empty."); - } - } - - @Test - public void basic_operations() - { - Stack<String> stack = newStack(); - - assertTrue(stack.isEmpty()); - - final String fred = "fred"; - final String barney = "barney"; - - stack.push(fred); - assertEquals(stack.peek(), fred); - assertFalse(stack.isEmpty()); - - stack.push(barney); - assertEquals(stack.peek(), barney); - - assertEquals(stack.toString(), "Stack[barney, fred]"); - - assertEquals(stack.getDepth(), 2); - - Object[] snapshot = stack.getSnapshot(); - - assertArraysEqual(snapshot, new Object[] {fred, barney}); - - assertEquals(stack.pop(), barney); - assertEquals(stack.peek(), fred); - - assertEquals(stack.pop(), fred); - assertTrue(stack.isEmpty()); - } - - @Test - public void expansion_of_inner_data() - { - final int LIMIT = 1000; - - Stack<Integer> stack = newStack(10); - - for (int i = 0; i < LIMIT; i++) - { - stack.push(i); - } - - for (int i = LIMIT - 1; i >= 0; i--) - { - assertEquals(stack.pop().intValue(), i); - } - } - - @Test - public void clear() - { - Stack<Integer> stack = newStack(); - - for (int i = 0; i < 10; i++) stack.push(i); - - assertEquals(stack.isEmpty(), false); - - stack.clear(); - - assertEquals(stack.isEmpty(), true); - } -}
