creadur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r1361744 - /creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java
Date Sun, 15 Jul 2012 17:43:23 GMT
Author: rdonkin
Date: Sun Jul 15 17:43:22 2012
New Revision: 1361744

URL: http://svn.apache.org/viewvc?rev=1361744&view=rev
Log:
Improve test coverage

Modified:
    creadur/whisker/trunk/apache-whisker-velocity/src/test/java/org/apache/creadur/whisker/out/velocity/TestLicenseGeneration.java

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=1361744&r1=1361743&r2=1361744&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 Jul 15 17:43:22 2012
@@ -24,10 +24,14 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.creadur.whisker.app.Result;
+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;
 
 import junit.framework.TestCase;
@@ -37,6 +41,7 @@ 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.";
@@ -57,8 +62,42 @@ public class TestLicenseGeneration exten
     protected void tearDown() throws Exception {
         super.tearDown();
     }
+
+    private void addDirectory(License license, final Organisation org,
+            final String directoryName) {
+        final WithinDirectory withinDirectory = buildDirectory(license, org,
+                directoryName);
+        contents.add(withinDirectory);
+    }
     
-    public void testThatWhenThereAreNoThirdPartyNoticesFooterIsNotShown() throws Exception
{
+    private Collection<Resource> buildResources() {
+        String noticeId = "notice:id";
+        notices.put(noticeId, "Some notice text");
+        Collection<Resource> resources = new ArrayList<Resource>();
+        String source = "";
+        String name = "resource";
+        resources.add(new Resource(name, 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>();
+        String copyright = "Copyright Blah";
+        Map<String, String> params = Collections.emptyMap();
+        withLicenses.add(new WithLicense(license, copyright, 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);
@@ -67,8 +106,25 @@ public class TestLicenseGeneration exten
 
         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 notices, expect that only the license text is output",

+        assertEquals("When no third party contents, expect that only the license text is
output", 
                 primaryLicenseText, 
                 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);
+        
+        assertFalse("Check that work is suitable for this test", work.isPrimaryOnly());
+        
+        subject.generate(work, writerFactory);
+
+        assertEquals("Only one request for LICENSE writer", 1, writerFactory.requestsFor(Result.LICENSE));
+        assertTrue("Expect information when third party contents present: " + writerFactory.firstOutputFor(Result.LICENSE),

+                StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE), 
+                        "This distribution contains third party resources."));
+    }
 }



Mime
View raw message