1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.creadur.whisker.model;
20
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.HashMap;
25 import java.util.Map;
26
27 import junit.framework.TestCase;
28
29 public class TestDescriptorRequiredNoticesWithRequiredThirdPartyNotices extends TestCase {
30
31 License primaryLicense = new License(false, "This is the license text", Collections.<String> emptyList(), "example.org", "http://example.org", "Example License");
32 String primaryOrg = "example.org";
33 String primaryNotice = "The primary notice.";
34 Collection<WithinDirectory> contents = new ArrayList<WithinDirectory>();
35 Map<String, License> licenses = new HashMap<String, License>();
36 Map<String, String> notices = new HashMap<String, String>();
37 Map<String, Organisation> organisations = new HashMap<String, Organisation>();
38
39 Descriptor subject;
40
41 protected void setUp() throws Exception {
42 super.setUp();
43 primaryLicense.storeIn(licenses);
44 String noticeId = "notice:id";
45 notices.put(noticeId, "Some notice text");
46 Collection<WithLicense> withLicenses = new ArrayList<WithLicense>();
47 License license = primaryLicense;
48 Collection<ByOrganisation> orgs = new ArrayList<ByOrganisation>();
49 Collection<Resource> resources = new ArrayList<Resource>();
50 String source = "";
51 String name = "resource";
52 resources.add(new Resource(name , noticeId, source));
53 String orgUrl = "org:url";
54 String orgId = "org:id";
55 String orgName = "example.org";
56 Organisation org = new Organisation(orgId, orgName, orgUrl);
57 orgs.add(new ByOrganisation(org, resources));
58 String copyright = "Copyright Blah";
59 Map<String, String> params = Collections.emptyMap();
60 withLicenses.add(new WithLicense(license, copyright, params, orgs));
61 Collection<ByOrganisation> publicDomain = Collections.emptyList();
62 contents.add(new WithinDirectory(".", withLicenses, publicDomain));
63 }
64
65 protected void tearDown() throws Exception {
66 super.tearDown();
67 }
68
69 public void testNoticeRequiredWhenPrimaryNoticeExists() throws Exception {
70 subject =
71 new Descriptor(primaryLicense, primaryOrg, primaryNotice,
72 licenses, notices, organisations, contents);
73 assertTrue("When primary notices exists and third party notices needed then display is required",
74 subject.isNoticeRequired());
75 }
76
77 public void testNoticeRequiredWhenPrimaryNoticeIsNullAndThirdPartyNotices() throws Exception {
78 subject =
79 new Descriptor(primaryLicense, primaryOrg, null,
80 licenses, notices, organisations, contents);
81 assertTrue("When no other notices exist and third party notices needed then display is required",
82 subject.isNoticeRequired());
83 }
84
85 public void testNoticeRequiredWhenPrimaryNoticeIsEmptyAndThirdPartyNotices() throws Exception {
86 subject =
87 new Descriptor(primaryLicense, primaryOrg, "",
88 licenses, notices, organisations, contents);
89 assertTrue("When no other notices exist and third party notices needed then display is required",
90 subject.isNoticeRequired());
91 }
92
93 public void testNoticeRequiredWhenPrimaryNoticeIsWhitespaceAndThirdPartyNotices() throws Exception {
94 subject =
95 new Descriptor(primaryLicense, primaryOrg, " ",
96 licenses, notices, organisations, contents);
97 assertTrue("When no other notices exist and third party notices needed then display is required",
98 subject.isNoticeRequired());
99 }
100 }