Skip to content

Commit 93a2da8

Browse files
ajozkarczews
authored andcommitted
Add missing license preambule, Enhancing UtilsVerifier docs, Fixing javadoc generator warnings (#6)
1 parent 58a4292 commit 93a2da8

File tree

4 files changed

+81
-18
lines changed

4 files changed

+81
-18
lines changed

src/main/java/com/github/karczews/utilsverifier/Arrays2.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Copyright (c) 2017-present, UtilsVerifier Contributors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
113
package com.github.karczews.utilsverifier;
214

315
/**

src/main/java/com/github/karczews/utilsverifier/UtilsVerifier.java

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import java.lang.reflect.Modifier;
2020

2121
/**
22-
* {@code EqualsVerifier} tool can be used in unit tests to verify if certain util class is
23-
* well formed.
22+
* {@code UtilsVerifier} tool can be used in unit tests to verify if certain
23+
* util class is well formed.
2424
* <p>
2525
* By default verifier performs following checks that class:
2626
* <ul>
@@ -29,8 +29,24 @@
2929
* <li> has no instance fields
3030
* <li> has no mutable static fields
3131
* </ul>
32+
* <p>
33+
* If any of the following checks fails then an {@link AssertionError} will be
34+
* thrown with an appropriate information about the cause.
35+
* <p>
36+
* Basic usage:
37+
* <pre>
38+
* {@code UtilsVerifier.forClass(TestedClass.class).verify();}
39+
* </pre>
40+
* It's not advised, but possible to suppress one or more of the checks with
41+
* builder methods.
42+
* <p>
43+
* Example suppress:
44+
* <pre>
45+
* {@code UtilsVerifier.forClass(TestClass.class).suppressFinalClassCheck(true).verify();}
46+
* </pre>
3247
*
3348
* @param <T> class under test
49+
* @see AssertionError
3450
*/
3551
public final class UtilsVerifier<T> {
3652

@@ -53,17 +69,22 @@ private UtilsVerifier(final Class<T> type) {
5369
}
5470

5571
/**
56-
* Creates UtilsVerifier instance for provided type.
72+
* Creates UtilsVerifier instance for the provided type.
5773
*
58-
* @param type class type for which verifier will be created
74+
* @param type class type for a which verifier will be created
75+
* @param <T> type of the class to verify
76+
* @return UtilsVerifier instance
5977
*/
6078
public static <T> UtilsVerifier<T> forClass(final Class<T> type) {
6179
return new UtilsVerifier<T>(type);
6280
}
6381

6482
/**
65-
* Performs verification for provided type.
66-
* {@link AssertionError} will be thrown if provided type is not well formed util class.
83+
* Performs verification for the type that the {@link UtilsVerifier} was
84+
* created with.
85+
* <p>
86+
* {@link AssertionError} will be thrown if provided type is not a well
87+
* formed util class.
6788
*/
6889
public void verify() {
6990
checkIfClassIsFinal();
@@ -78,6 +99,7 @@ public void verify() {
7899
* Sets exception type that will be expected during construction attempt.
79100
*
80101
* @param type expected exception type
102+
* @return UtilsVerifier instance
81103
*/
82104
public UtilsVerifier<T> withConstructorThrowing(final Class<? extends Throwable> type) {
83105
expectedConstructorException = type;
@@ -88,61 +110,67 @@ public UtilsVerifier<T> withConstructorThrowing(final Class<? extends Throwable>
88110
* Suppress final class verification. Use if non-final util class is allowed.
89111
*
90112
* @param suppressCheck true if check should be suppressed, false otherwise
113+
* @return UtilsVerifier instance
91114
*/
92115
public UtilsVerifier<T> suppressFinalClassCheck(final boolean suppressCheck) {
93116
suppressFinalClassCheck = suppressCheck;
94117
return this;
95118
}
96119

97120
/**
98-
* Suppress single constructor verification.
99-
* Use if util class is allowed to have more than one constructor.
121+
* Suppress single constructor verification. Use if util class is allowed to
122+
* have more than one constructor.
100123
*
101124
* @param suppressCheck true if check should be suppressed, false otherwise
125+
* @return UtilsVerifier instance
102126
*/
103127
public UtilsVerifier<T> suppressOnlyOneConstructorCheck(final boolean suppressCheck) {
104128
suppressOnlyOneConstructorCheck = suppressCheck;
105129
return this;
106130
}
107131

108132
/**
109-
* Suppress private constructor verification.
110-
* Use if util class is allowed to have non private constructor.
133+
* Suppress private constructor verification. Use if util class is allowed
134+
* to have non private constructor.
111135
*
112136
* @param suppressCheck true if check should be suppressed, false otherwise
137+
* @return UtilsVerifier instance
113138
*/
114139
public UtilsVerifier<T> suppressPrivateConstructorCheck(final boolean suppressCheck) {
115140
suppressPrivateConstructorCheck = suppressCheck;
116141
return this;
117142
}
118143

119144
/**
120-
* Suppress instance field verification.
121-
* Use if util class is allowed to have instance fields.
145+
* Suppress instance field verification. Use if util class is allowed to
146+
* have instance fields.
122147
*
123148
* @param suppressCheck true if check should be suppressed, false otherwise
149+
* @return UtilsVerifier instance
124150
*/
125151
public UtilsVerifier<T> suppressInstanceFieldCheck(final boolean suppressCheck) {
126152
suppressInstanceFieldCheck = suppressCheck;
127153
return this;
128154
}
129155

130156
/**
131-
* Suppress instance method verification.
132-
* Use if util class is allowed to have instance methods.
157+
* Suppress instance method verification. Use if util class is allowed to
158+
* have instance methods.
133159
*
134160
* @param suppressCheck true if check should be suppressed, false otherwise
161+
* @return UtilsVerifier instance
135162
*/
136163
public UtilsVerifier<T> suppressInstanceMethodCheck(final boolean suppressCheck) {
137164
suppressInstanceMethodCheck = suppressCheck;
138165
return this;
139166
}
140167

141168
/**
142-
* Suppress static mutable fields verification.
143-
* Use if util class is allowed to have mutable static fields.
169+
* Suppress static mutable fields verification. Use if util class is allowed
170+
* to have mutable static fields.
144171
*
145172
* @param suppressCheck true if check should be suppressed, false otherwise
173+
* @return UtilsVerifier instance
146174
*/
147175
public UtilsVerifier<T> suppressMutableStaticFieldsCheck(final boolean suppressCheck) {
148176
suppressMutableStaticFieldsCheck = suppressCheck;
@@ -218,12 +246,11 @@ private void hasNoMutableStaticFields() {
218246
if (suppressMutableStaticFieldsCheck) return;
219247
final Field[] fields = classUnderTest.getDeclaredFields();
220248

221-
fields:
222249
for (int index = 0; index < fields.length; index++) {
223250
final Field field = fields[index];
224251
final int modifiers = field.getModifiers();
225252
if (Arrays2.contains(field.getName(), allowedMutableStaticFields)) {
226-
continue fields;
253+
continue;
227254
}
228255
if (Modifier.isStatic(modifiers) && !Modifier.isFinal(modifiers)) {
229256
throw new AssertionError(classUnderTest.getName()

src/test/java/com/github/karczews/utilsverifier/subjects/ImmutableStaticFields.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Copyright (c) 2017-present, UtilsVerifier Contributors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
113
package com.github.karczews.utilsverifier.subjects;
214

315
public final class ImmutableStaticFields {

src/test/java/com/github/karczews/utilsverifier/subjects/MutableStaticFields.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
/**
2+
* Copyright (c) 2017-present, UtilsVerifier Contributors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5+
* compliance with the License. You may obtain a copy of the License at
6+
* <p>
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* <p>
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is
10+
* distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11+
* the License for the specific language governing permissions and limitations under the License.
12+
*/
113
package com.github.karczews.utilsverifier.subjects;
214

315
public final class MutableStaticFields {

0 commit comments

Comments
 (0)