1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.testhelpers;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.apache.rat.analysis.IHeaderMatcher;
23 import org.apache.rat.analysis.IHeaders;
24 import org.apache.rat.license.ILicense;
25 import org.apache.rat.license.ILicenseFamily;
26
27
28
29
30 public class TestingLicense implements ILicense {
31
32 private final ILicenseFamily family;
33 private final IHeaderMatcher matcher;
34 private final String note;
35 private String name;
36 private final String id;
37
38
39
40
41
42
43 public TestingLicense(String id) {
44 this(id, id, new TestingMatcher());
45 }
46
47
48
49
50
51
52
53 public TestingLicense(String family, String id) {
54 this(family, id, new TestingMatcher());
55 }
56
57
58
59
60
61
62 public TestingLicense(String family, String id, IHeaderMatcher matcher) {
63 this(id, matcher, ILicenseFamily.builder().setLicenseFamilyCategory(family)
64 .setLicenseFamilyName("TestingLicense: " + family).build());
65 }
66
67
68
69
70
71
72
73 public TestingLicense(String id, IHeaderMatcher matcher, ILicenseFamily family) {
74 this.family = family;
75 this.matcher = matcher;
76 this.note = null;
77 this.id = id;
78 this.name = id;
79 }
80
81
82
83
84
85 public ILicenseFamily getFamily() {
86 return family;
87 }
88
89
90
91
92
93 @Override
94 public IHeaderMatcher getMatcher() {
95 return matcher;
96 }
97
98
99
100
101
102 public void setName(String name) {
103 this.name = name;
104 }
105
106 @Override
107 public String getId() {
108 return id;
109 }
110
111 @Override
112 public void reset() {
113 matcher.reset();
114 }
115
116 @Override
117 public boolean matches(IHeaders line) {
118 return matcher.matches(line);
119 }
120
121 @Override
122 public ILicenseFamily getLicenseFamily() {
123 return family;
124 }
125
126 @Override
127 public String getNote() {
128 return note;
129 }
130
131 @Override
132 public String getName() {
133 return StringUtils.defaultIfBlank(name, family.getFamilyName());
134 }
135
136 @Override
137 public boolean equals(Object o) {
138 return ILicense.equals(this, o);
139 }
140
141 @Override
142 public int hashCode() {
143 return ILicense.hash(this);
144 }
145
146 @Override
147 public String toString() {
148 return String.format("%s[id='%s', family='%s']", name, id, family);
149 }
150 }