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.aConfiguration;
22 import junit.framework.TestCase;
23
24 import org.apache.commons.lang3.StringUtils;
25 import org.apache.creadur.whisker.app.Result;
26 import org.apache.creadur.whisker.model.Descriptor;
27
28 public class TestLicenseGenerationSourceURLs extends TestCase {
29
30 StringResultWriterFactory writerFactory;
31 VelocityEngine subject;
32 DescriptorBuilderForTesting builder;
33 Descriptor work;
34
35 @Override
36 protected void setUp() throws Exception {
37 super.setUp();
38 writerFactory = new StringResultWriterFactory();
39 subject = new VelocityEngine(new EmptyLog());
40 builder = new DescriptorBuilderForTesting().withSourceURL();
41 work = builder.withPrimaryLicenseAndThirdPartyOrgInDirectory(".").build();
42 }
43
44 @Override
45 protected void tearDown() throws Exception {
46 super.tearDown();
47 }
48
49 public void testNoSourceUrlsConfiguration() throws Exception {
50 subject.generate(work, writerFactory, aConfiguration().noSourceURLsInLicense().build());
51 assertFalse(failureMessage(), outputContainsSourceUrl());
52
53 }
54
55 private boolean outputContainsSourceUrl() {
56 return StringUtils.contains(writerFactory.firstOutputFor(Result.LICENSE),
57 builder.sourceUrl);
58 }
59
60 private String failureMessage() {
61 return "Expect information when third party contents present: " + writerFactory.firstOutputFor(Result.LICENSE);
62 }
63
64 public void testWithSourceUrlsConfiguration() throws Exception {
65 subject.generate(work, writerFactory, aConfiguration().withSourceURLsInLicense().build());
66
67 assertTrue(failureMessage(), outputContainsSourceUrl());
68
69 }
70 }