1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.creadur.whisker.out.velocity;
20
21 import static org.apache.creadur.whisker.app.ConfigurationBuilder.*;
22
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.HashMap;
27 import java.util.Map;
28
29 import org.apache.creadur.whisker.app.Result;
30 import org.apache.creadur.whisker.model.Descriptor;
31 import org.apache.creadur.whisker.model.License;
32 import org.apache.creadur.whisker.model.Organisation;
33 import org.apache.creadur.whisker.model.WithinDirectory;
34
35 import junit.framework.TestCase;
36
37 public class TestNoticeGeneration extends TestCase {
38
39 StringResultWriterFactory writerFactory;
40 LoggingVelocityEngine subject;
41 License primaryLicense = new License(false, "This is the license text", Collections.<String> emptyList(), "example.org", "http://example.org", "Example License");
42 String primaryOrg = "example.org";
43 String primaryNotice = "The primary notice.";
44 Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
45 Map<String, License> licenses = new HashMap<String, License>();
46 Map<String, String> notices = new HashMap<String, String>();
47 Map<String, Organisation> organisations = new HashMap<String, Organisation>();
48
49 @Override
50 protected void setUp() throws Exception {
51 super.setUp();
52 writerFactory = new StringResultWriterFactory();
53 subject = new LoggingVelocityEngine();
54 primaryLicense.storeIn(licenses);
55 }
56
57 @Override
58 protected void tearDown() throws Exception {
59 super.tearDown();
60 }
61
62 public void testThatWhenThereAreNoThirdPartyNoticesHeaderIsNotShown() throws Exception {
63 Descriptor work =
64 new Descriptor(primaryLicense, primaryOrg, primaryNotice,
65 licenses, notices, organisations, contents);
66
67 subject.generate(work, writerFactory, aConfiguration().build());
68
69 assertEquals("Only one request for NOTICE writer", 1, writerFactory.requestsFor(Result.NOTICE));
70 assertEquals("When no third party notices, expect that only the primary notice is output", primaryNotice, writerFactory.firstOutputFor(Result.NOTICE).trim());
71 }
72
73 public void testThatNoticeOutputIsSkippedWhenThereAreNoNotices() throws Exception {
74 Descriptor work =
75 new Descriptor(primaryLicense, primaryOrg, "",
76 licenses, notices, organisations, contents);
77
78 subject.generate(work, writerFactory, aConfiguration().build());
79
80 assertEquals("No requests for NOTICE writer", 0, writerFactory.requestsFor(Result.NOTICE));
81 }
82
83 }