You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2012/05/16 20:50:31 UTC

[25/44] git commit: Convert TestNG to Spock

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/2343afb8
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/2343afb8
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/2343afb8

Branch: refs/heads/master
Commit: 2343afb87f1e272bc5dc28b06f248e29a537c69e
Parents: aa452c7
Author: Howard M. Lewis Ship <hl...@gmail.com>
Authored: Tue May 1 13:42:07 2012 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Wed May 16 11:50:13 2012 -0700

----------------------------------------------------------------------
 .../services/ExceptionAnalyzerImplSpec.groovy      |  216 +++++++++++++++
 .../services/ExceptionAnalyzerImplTest.java        |  215 --------------
 .../services/WriteOnlyPropertyException.java       |   34 ---
 3 files changed, 216 insertions(+), 249 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/2343afb8/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplSpec.groovy
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplSpec.groovy b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplSpec.groovy
new file mode 100644
index 0000000..f5f63b0
--- /dev/null
+++ b/tapestry-ioc/src/test/groovy/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplSpec.groovy
@@ -0,0 +1,216 @@
+package org.apache.tapestry5.ioc.internal.services
+
+import org.apache.tapestry.ioc.AbstractSharedRegistrySpecification
+import org.apache.tapestry5.ioc.Location
+import org.apache.tapestry5.ioc.internal.util.TapestryException
+import org.apache.tapestry5.ioc.services.ExceptionAnalyzer
+
+class WriteOnlyPropertyException extends Exception
+{
+  private String code;
+
+  public String getCode()
+  {
+    return code;
+  }
+
+  public void setFaultCode(int code)
+  {
+    this.code = String.format("%04d", code);
+  }
+}
+
+class SelfCausedException extends RuntimeException {
+  SelfCausedException(String message) {
+    super(message);
+  }
+
+  public Throwable getCause() {
+    return this;
+  }
+}
+
+class ExceptionAnalyzerImplSpec extends AbstractSharedRegistrySpecification {
+
+  ExceptionAnalyzer analyzer = getService(ExceptionAnalyzer)
+
+  def "analysis of a simple exception"() {
+    when:
+    def ea = analyzer.analyze(t)
+
+    then:
+
+    ea.exceptionInfos.size() == 1
+
+    def ei = ea.exceptionInfos[0]
+
+    ei.className == RuntimeException.name
+    ei.message == message
+
+    ei.propertyNames.empty
+    !ei.stackTrace.empty
+
+    where:
+
+    message = "Hey! We've Got No Tomatoes"
+    t = new RuntimeException(message)
+  }
+
+  def "access to properties of exception"() {
+    Location l = Mock()
+    def t = new TapestryException("Message", l, null)
+
+    when:
+    def ea = analyzer.analyze(t)
+
+    then:
+
+    ea.exceptionInfos.size() == 1
+
+    def ei = ea.exceptionInfos[0]
+
+    ei.propertyNames == ["location"]
+    ei.getProperty("location").is(l)
+  }
+
+  def "access to nested exceptions"() {
+    when:
+
+    def ea = analyzer.analyze(outer)
+
+    then:
+
+    ea.exceptionInfos.size() == 2
+
+    def ei = ea.exceptionInfos[0]
+
+    ei.message == "Outer"
+    ei.stackTrace.empty
+
+    when:
+
+    ei = ea.exceptionInfos[1]
+
+    then:
+
+    ei.message == "Inner"
+    !ei.stackTrace.empty
+
+    where:
+
+    inner = new RuntimeException("Inner")
+    outer = new RuntimeException("Outer", inner)
+  }
+
+  def "middle exception that adds no value is removed"() {
+    when:
+
+    def ea = analyzer.analyze(outer)
+
+    then:
+
+    ea.exceptionInfos.size() == 2
+
+    def ei = ea.exceptionInfos[0]
+
+    ei.message == "Outer: Middle"
+    ei.stackTrace.empty
+
+    when:
+
+    ei = ea.exceptionInfos[1]
+
+    then:
+
+    ei.message == "Inner"
+
+    !ei.stackTrace.empty
+
+    where:
+
+    inner = new RuntimeException("Inner");
+    middle = new RuntimeException("Middle", inner);
+    outer = new RuntimeException("Outer: Middle", middle);
+  }
+
+  def "a middle exception that adds extra information is retained"() {
+    Location l = Mock()
+    def inner = new RuntimeException("Inner");
+    def middle = new TapestryException("Middle", l, inner);
+    def outer = new RuntimeException("Outer: Middle", middle);
+
+    when:
+
+    def ea = analyzer.analyze(outer)
+
+    then:
+
+    ea.exceptionInfos.size() == 3
+
+    def ei = ea.exceptionInfos[0]
+
+    ei.message == "Outer: Middle"
+    ei.stackTrace.empty
+
+    when:
+
+    ei = ea.exceptionInfos[1]
+
+    then:
+
+    ei.message == "Middle"
+    ei.getProperty("location").is(l)
+    ei.stackTrace.empty
+
+    when:
+
+    ei = ea.exceptionInfos[2]
+
+    then:
+
+    ei.message == "Inner"
+    !ei.stackTrace.empty
+  }
+
+  def "write only properties are omitted"() {
+    WriteOnlyPropertyException ex = new WriteOnlyPropertyException();
+
+    ex.setFaultCode(99);
+
+    when:
+
+    def ea = analyzer.analyze(ex);
+
+    then:
+
+    def ei = ea.exceptionInfos[0]
+
+    ei.propertyNames.contains("code")
+    ! ei.propertyNames.contains("faultCode")
+    ei.getProperty("code") == "0099"
+  }
+
+  def "an exception that is its own cause does not cause an endless loop"() {
+    when:
+
+    def ea = analyzer.analyze(t)
+
+    then:
+
+    ea.exceptionInfos.size() == 1
+
+    def ei = ea.exceptionInfos[0]
+
+    ei.className == SelfCausedException.name
+    ei.message == message
+
+    !ei.propertyNames.contains("cause")
+
+    !ei.stackTrace.empty
+
+    where:
+
+    message = "Who you lookin at?"
+    t = new SelfCausedException(message)
+  }
+}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/2343afb8/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java
deleted file mode 100644
index 9c60d74..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/ExceptionAnalyzerImplTest.java
+++ /dev/null
@@ -1,215 +0,0 @@
-// Copyright 2006, 2007, 2010 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.internal.services;
-
-import org.apache.tapestry5.ioc.Location;
-import org.apache.tapestry5.ioc.internal.IOCInternalTestCase;
-import org.apache.tapestry5.ioc.internal.util.TapestryException;
-import org.apache.tapestry5.ioc.services.ExceptionAnalysis;
-import org.apache.tapestry5.ioc.services.ExceptionAnalyzer;
-import org.apache.tapestry5.ioc.services.ExceptionInfo;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import java.util.Arrays;
-
-public class ExceptionAnalyzerImplTest extends IOCInternalTestCase
-{
-    private ExceptionAnalyzer analyzer;
-
-    @BeforeClass
-    public void setup_analyzer()
-    {
-        analyzer = getService("ExceptionAnalyzer", ExceptionAnalyzer.class);
-    }
-
-    @AfterClass
-    public void cleanup_analyzer()
-    {
-        analyzer = null;
-    }
-
-    @Test
-    public void basic_exception()
-    {
-        String message = "Hey! We've Got Not Tomatoes!";
-
-        Throwable t = new RuntimeException(message);
-
-        ExceptionAnalysis ea = analyzer.analyze(t);
-
-        assertEquals(ea.getExceptionInfos().size(), 1);
-
-        ExceptionInfo ei = ea.getExceptionInfos().get(0);
-
-        assertEquals(ei.getClassName(), RuntimeException.class.getName());
-        assertEquals(ei.getMessage(), message);
-
-        assertTrue(ei.getPropertyNames().isEmpty());
-        assertFalse(ei.getStackTrace().isEmpty());
-    }
-
-    @Test
-    public void exception_properties()
-    {
-        Location l = mockLocation();
-
-        replay();
-
-        Throwable t = new TapestryException("Message", l, null);
-
-        ExceptionAnalysis ea = analyzer.analyze(t);
-
-        assertEquals(ea.getExceptionInfos().size(), 1);
-
-        ExceptionInfo ei = ea.getExceptionInfos().get(0);
-
-        assertEquals(ei.getPropertyNames(), Arrays.asList("location"));
-
-        assertEquals(ei.getProperty("location"), l);
-
-        verify();
-    }
-
-    @Test
-    public void nested_exceptions()
-    {
-        Throwable inner = new RuntimeException("Inner");
-        Throwable outer = new RuntimeException("Outer", inner);
-
-        ExceptionAnalysis ea = analyzer.analyze(outer);
-
-        assertEquals(ea.getExceptionInfos().size(), 2);
-
-        ExceptionInfo ei = ea.getExceptionInfos().get(0);
-
-        assertEquals(ei.getMessage(), "Outer");
-        assertTrue(ei.getStackTrace().isEmpty());
-
-        ei = ea.getExceptionInfos().get(1);
-
-        assertEquals(ei.getMessage(), "Inner");
-        assertFalse(ei.getStackTrace().isEmpty());
-    }
-
-    @Test
-    public void middle_exception_removed_with_no_value()
-    {
-        Throwable inner = new RuntimeException("Inner");
-        Throwable middle = new RuntimeException("Middle", inner);
-        Throwable outer = new RuntimeException("Outer: Middle", middle);
-
-        ExceptionAnalysis ea = analyzer.analyze(outer);
-
-        assertEquals(ea.getExceptionInfos().size(), 2);
-
-        ExceptionInfo ei = ea.getExceptionInfos().get(0);
-
-        assertEquals(ei.getMessage(), "Outer: Middle");
-        assertTrue(ei.getStackTrace().isEmpty());
-
-        ei = ea.getExceptionInfos().get(1);
-
-        assertEquals(ei.getMessage(), "Inner");
-        assertFalse(ei.getStackTrace().isEmpty());
-    }
-
-    @Test
-    public void middle_exception_retained_due_to_extra_property()
-    {
-        Location l = mockLocation();
-
-        replay();
-
-        Throwable inner = new RuntimeException("Inner");
-        Throwable middle = new TapestryException("Middle", l, inner);
-        Throwable outer = new RuntimeException("Outer: Middle", middle);
-
-        ExceptionAnalysis ea = analyzer.analyze(outer);
-
-        assertEquals(ea.getExceptionInfos().size(), 3);
-
-        ExceptionInfo ei = ea.getExceptionInfos().get(0);
-
-        assertEquals(ei.getMessage(), "Outer: Middle");
-        assertTrue(ei.getStackTrace().isEmpty());
-
-        ei = ea.getExceptionInfos().get(1);
-
-        assertEquals(ei.getMessage(), "Middle");
-        assertTrue(ei.getStackTrace().isEmpty());
-
-        ei = ea.getExceptionInfos().get(2);
-
-        assertEquals(ei.getMessage(), "Inner");
-        assertFalse(ei.getStackTrace().isEmpty());
-
-        verify();
-    }
-
-    /**
-     * TAPESTRY-2422
-     */
-    @Test
-    public void exception_with_write_only_property()
-    {
-        WriteOnlyPropertyException ex = new WriteOnlyPropertyException();
-
-        ex.setFaultCode(99);
-
-        ExceptionAnalysis ea = analyzer.analyze(ex);
-
-        ExceptionInfo ei = ea.getExceptionInfos().get(0);
-
-        assertEquals(ei.getPropertyNames().size(), 1);
-
-        assertEquals(ei.getProperty("code"), "0099");
-    }
-
-    @SuppressWarnings("all")
-    public static class SelfCausedException extends RuntimeException
-    {
-        public SelfCausedException(String message)
-        {
-            super(message);
-        }
-
-        public Throwable getCause()
-        {
-            return this;
-        }
-    }
-
-    @Test
-    public void exception_that_is_its_own_cause()
-    {
-        String message = "Hey! We've Got Not Tomatoes!";
-
-        Throwable t = new SelfCausedException(message);
-
-        ExceptionAnalysis ea = analyzer.analyze(t);
-
-        assertEquals(ea.getExceptionInfos().size(), 1);
-
-        ExceptionInfo ei = ea.getExceptionInfos().get(0);
-
-        assertEquals(ei.getClassName(), SelfCausedException.class.getName());
-        assertEquals(ei.getMessage(), message);
-
-        assertTrue(ei.getPropertyNames().isEmpty());
-        assertFalse(ei.getStackTrace().isEmpty());
-    }
-}

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/2343afb8/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/WriteOnlyPropertyException.java
----------------------------------------------------------------------
diff --git a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/WriteOnlyPropertyException.java b/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/WriteOnlyPropertyException.java
deleted file mode 100644
index 5215c1e..0000000
--- a/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/WriteOnlyPropertyException.java
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 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.internal.services;
-
-/**
- * Used to test {@link org.apache.tapestry5.ioc.internal.services.ExceptionAnalyzerImpl} against an exception that has a
- * write-only property.
- */
-public class WriteOnlyPropertyException extends Exception
-{
-    private String code;
-
-    public String getCode()
-    {
-        return code;
-    }
-
-    public void setFaultCode(int code)
-    {
-        this.code = String.format("%04d", code);
-    }
-}