creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r1408073 - in /creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity: DescriptorBuilderForTesting.java TestLicenseGeneration.java
Date Sun, 11 Nov 2012 18:30:55 GMT
Author: rdonkin
Date: Sun Nov 11 18:30:54 2012
New Revision: 1408073

URL: http://svn.apache.org/viewvc?rev=1408073&view=rev
Log:
Simply test class by factoring out building logic. 

Added:
    creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java
  (with props)
Modified:
    creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java

Added: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java?rev=1408073&view=auto
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java
(added)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java
Sun Nov 11 18:30:54 2012
@@ -0,0 +1,143 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.creadur.whisker.out.velocity;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.creadur.whisker.model.ByOrganisation;
+import org.apache.creadur.whisker.model.Descriptor;
+import org.apache.creadur.whisker.model.License;
+import org.apache.creadur.whisker.model.Organisation;
+import org.apache.creadur.whisker.model.Resource;
+import org.apache.creadur.whisker.model.WithLicense;
+import org.apache.creadur.whisker.model.WithinDirectory;
+
+public class DescriptorBuilderForTesting {
+
+    private static final String A_PRIMARY_COPYRIGHT_NOTICE = "Copyright (c) this is primary";
+    String primaryLicenseText = "This is the primary license text";
+    Organisation thirdPartyOrg = new Organisation("third-party", "thirdparty.org", "http://thirdparty.org");
+    License primaryLicense = new License(false, primaryLicenseText, Collections.<String>
emptyList(), "example.org", "http://example.org", "Example License");
+    String primaryOrgName = "example.org";
+    String primaryNotice = "The primary notice.";
+    Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
+    Map<String, License> licenses = new HashMap<String, License>();
+    Map<String, String> notices = new HashMap<String, String>();
+    Map<String, Organisation> organisations = new HashMap<String, Organisation>();
+    String secondaryCopyright;
+    String resourceName;
+    String primaryCopyrightNotice = null;
+
+    public DescriptorBuilderForTesting() {
+        resourceName = "resource";
+        secondaryCopyright = "Copyright (c) this is secondary";
+        primaryLicense.storeIn(licenses);
+    }
+
+    public DescriptorBuilderForTesting withPrimaryLicenseAndOrgInDirectory(String directoryName)
{
+        addDirectory(getPrimaryLicense(), primaryOrganisation(), directoryName);
+        return this;
+    }
+
+
+    public DescriptorBuilderForTesting withPrimaryLicenseAndThirdPartyOrgInDirectory(String
directoryName) {
+        addDirectory(getPrimaryLicense(), getThirdPartyOrg(), directoryName);
+        return this;
+    }
+
+    public Organisation primaryOrganisation() {
+        return new Organisation(getPrimaryOrgName(), "primary.org", "http://example.org");
+    }
+
+    public Descriptor build() {
+        return new Descriptor(primaryLicense, primaryCopyrightNotice, primaryOrgName,
+                primaryNotice, licenses, notices, organisations, contents);
+    }
+
+    public String getResourceName() {
+        return resourceName;
+    }
+
+    public String getSecondaryCopyright() {
+        return secondaryCopyright;
+    }
+
+    public String getPrimaryOrgName() {
+        return primaryOrgName;
+    }
+
+    public Organisation getThirdPartyOrg() {
+        return thirdPartyOrg;
+    }
+
+    public License getPrimaryLicense() {
+        return primaryLicense;
+    }
+
+    public String getPrimaryLicenseText() {
+        return primaryLicenseText;
+    }
+
+    public void addDirectory(License license, final Organisation org,
+            final String directoryName) {
+        final WithinDirectory withinDirectory = buildDirectory(license, org,
+                directoryName);
+        contents.add(withinDirectory);
+    }
+
+    private Collection<Resource> buildResources() {
+        String noticeId = "notice:id";
+        notices.put(noticeId, "Some notice text");
+        Collection<Resource> resources = new ArrayList<Resource>();
+        String source = "";
+        resources.add(new Resource(resourceName, noticeId, source));
+        return resources;
+    }
+
+    private WithinDirectory buildDirectory(License license,
+            final Organisation org, final String directoryName) {
+        Collection<ByOrganisation> byOrgs = new ArrayList<ByOrganisation>();
+        Collection<Resource> resources = buildResources();
+        byOrgs.add(new ByOrganisation(org, resources));
+
+        Collection<WithLicense> withLicenses = new ArrayList<WithLicense>();
+        Map<String, String> params = Collections.emptyMap();
+        withLicenses.add(new WithLicense(license, secondaryCopyright, params, byOrgs));
+
+        Collection<ByOrganisation> publicDomain = Collections.emptyList();
+
+        final WithinDirectory withinDirectory = new WithinDirectory(directoryName, withLicenses,
publicDomain);
+        return withinDirectory;
+    }
+
+    public DescriptorBuilderForTesting withPrimaryCopyrightNotice() {
+        return withPrimaryCopyrightNotice(A_PRIMARY_COPYRIGHT_NOTICE);
+    }
+
+
+    public DescriptorBuilderForTesting withPrimaryCopyrightNotice(String primaryCopyrightNotice)
{
+        this.primaryCopyrightNotice = primaryCopyrightNotice;
+        return this;
+    }
+
+}

Propchange: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/DescriptorBuilderForTesting.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java
URL: http://svn.apache.org/viewvc/creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java?rev=1408073&r1=1408072&r2=1408073&view=diff
==============================================================================
--- creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java
(original)
+++ creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java
Sun Nov 11 18:30:54 2012
@@ -40,26 +40,14 @@ public class TestLicenseGeneration exten
 
     StringResultWriterFactory writerFactory;
     VelocityEngine subject;
-    String primaryLicenseText = "This is the primary license text";
-    Organisation thirdPartyOrg = new Organisation("third-party", "thirdparty.org", "http://thirdparty.org");
-    License primaryLicense = new License(false, primaryLicenseText, Collections.<String>
emptyList(), "example.org", "http://example.org", "Example License");
-    String primaryOrg = "example.org";
-    String primaryNotice = "The primary notice.";
-    Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
-    Map<String, License> licenses = new HashMap<String, License>();
-    Map<String, String> notices = new HashMap<String, String>();
-    Map<String, Organisation> organisations = new HashMap<String, Organisation>();
-    String secondaryCopyright;
-    String resourceName;
+    DescriptorBuilderForTesting builder;
 
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        resourceName = "resource";
-        secondaryCopyright = "Copyright (c) this is secondary";
         writerFactory = new StringResultWriterFactory();
         subject = new VelocityEngine(new EmptyLog());
-        primaryLicense.storeIn(licenses);
+        builder = new DescriptorBuilderForTesting();
     }
 
     @Override
@@ -67,58 +55,21 @@ public class TestLicenseGeneration exten
         super.tearDown();
     }
 
-    private void addDirectory(License license, final Organisation org,
-            final String directoryName) {
-        final WithinDirectory withinDirectory = buildDirectory(license, org,
-                directoryName);
-        contents.add(withinDirectory);
-    }
-
-    private Collection<Resource> buildResources() {
-        String noticeId = "notice:id";
-        notices.put(noticeId, "Some notice text");
-        Collection<Resource> resources = new ArrayList<Resource>();
-        String source = "";
-        resources.add(new Resource(resourceName, noticeId, source));
-        return resources;
-    }
-
-    private WithinDirectory buildDirectory(License license,
-            final Organisation org, final String directoryName) {
-        Collection<ByOrganisation> byOrgs = new ArrayList<ByOrganisation>();
-        Collection<Resource> resources = buildResources();
-        byOrgs.add(new ByOrganisation(org, resources));
-
-        Collection<WithLicense> withLicenses = new ArrayList<WithLicense>();
-        Map<String, String> params = Collections.emptyMap();
-        withLicenses.add(new WithLicense(license, secondaryCopyright, params, byOrgs));
-
-        Collection<ByOrganisation> publicDomain = Collections.emptyList();
-
-        final WithinDirectory withinDirectory = new WithinDirectory(directoryName, withLicenses,
publicDomain);
-        return withinDirectory;
-    }
 
     public void testThatWhenThereAreNoThirdPartyContentsFooterIsNotShown() throws Exception
{
-        Descriptor work =
-                new Descriptor(primaryLicense, primaryOrg,  primaryNotice,
-                        licenses, notices, organisations, contents);
+        Descriptor work = builder.build();
 
         subject.generate(work, writerFactory);
 
         assertTrue("Check that work is suitable for this test", work.isPrimaryOnly());
         assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE));
         assertEquals("When no third party contents, expect that only the license text is
output",
-                primaryLicenseText,
+                builder.getPrimaryLicenseText(),
                 writerFactory.firstOutputFor(Result.LICENSE).trim());
     }
 
     public void testThatFooterIsShownWhenThereAreThirdPartyContents() throws Exception {
-        addDirectory(primaryLicense, thirdPartyOrg, "lib");
-
-        Descriptor work =
-                new Descriptor(primaryLicense, primaryOrg,  primaryNotice,
-                        licenses, notices, organisations, contents);
+        Descriptor work = builder.withPrimaryLicenseAndThirdPartyOrgInDirectory("lib").build();
 
         assertFalse("Check that work is suitable for this test", work.isPrimaryOnly());
 
@@ -131,21 +82,18 @@ public class TestLicenseGeneration exten
     }
 
     public void testSecondaryCopyrightNoticeForPrimaryLicense() throws Exception {
-        final String primaryCopyrightNotice = "Copyright (c) this is primary";
-        addDirectory(primaryLicense, new Organisation(primaryOrg, "primary.org", "http://example.org"),
"lib");
-        Descriptor work =
-                new Descriptor(primaryLicense, primaryCopyrightNotice, primaryOrg,  primaryNotice,
-                        licenses, notices, organisations, contents);
+        Descriptor work = builder.withPrimaryCopyrightNotice().withPrimaryLicenseAndOrgInDirectory("lib").build();
 
         subject.generate(work, writerFactory);
 
         assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE));
         assertTrue("Expect secondary copyright to be presented: " + writerFactory.firstOutputFor(Result.LICENSE),
                 StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE),
-                        secondaryCopyright));
+                        builder.getSecondaryCopyright()));
         assertTrue("Expect resource to be indicated: " + writerFactory.firstOutputFor(Result.LICENSE),
                 StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE),
-                        resourceName));
+                        builder.getResourceName()));
 
     }
+
 }



Mime
View raw message