Skip to content

Commit fd954c0

Browse files
- Add codecov support (#1)
- Add license header to sources - Update README.md - Add sonatype snapshots configuration.
1 parent d704355 commit fd954c0

File tree

13 files changed

+210
-47
lines changed

13 files changed

+210
-47
lines changed

.travis.yml

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
language: java
22
jdk: oraclejdk8
33
sudo: false
4-
4+
install: true
55
script:
6-
- ./gradlew clean build test check
7-
6+
- "./gradlew clean build test check jacocoTestReport"
7+
after_success:
8+
- bash <(curl -s https://codecov.io/bash)
9+
- ".utility/initiate-publish.sh"
810
cache:
911
directories:
10-
- $HOME/.gradle
12+
- "$HOME/.gradle"
13+
env:
14+
global:
15+
- secure: fMNepzdo/3x6Hf3H5KzxTJ4zzsJ8aIoseZLAOgpp/BuCexp7Pq6urbycmZ3VRd3yeYou/SBesockVjyVw4CULhx7dr9Q28+YUvlS/k5n0dcVqeICeS43A0YafdrsUFKPJrvs+Jl3e67y99uLVGHPXe1ntkYzjnF7g3rDpmxwmkE5kchV3cUZeSAJZIarU287fo5JuhtOXwnICYR6/oSJmok4xJcBbKQeGvqYmhkHm/7gHuYyhVwDvM3UTUodzrOP3PM0B4e4kvYG6olqdlFPiuj6LbKrvWU2Z6WVAyNw7zbe9F5cYqXZOs1VBgG381hWb6+JtZ8t6dKl+Z5/HnOiUhm2Xlj6oGA7EVXknWWtZLiiF5GjmkNWk/b2ERZGwA/KN102xnXhCdg9Cs14xqpYGh++f7QMTBW2JWRooMshisy30I/3jxz1lF6Gq8TZi7QtV5VMS0jnrY60A18N3HM4UrR8XYd5xMa4PlllGLkqlkTUlOUSYU4eCV8W+ElYeitMCKFcb/HfhiLFc/3TCyMddlfA7BQVTfkGEmUe9hpufL/098axUBQ8hop7Bpd2OFTcZ5f+KfHqQEn4mswEKkkcw7hcTl+RVeHQcZOwdAh7h1bpfR4R2YxuDBv4Yw6cqtCwz/IF7GugdFJq5Yi58eqNhV7D35ArNH2xUX5t1qal7E4=
16+
- secure: HaHgFdwu1Pb7GlXM/hvnPMMPHwPBvUshZS4w2VKYKAxHZAvbsvzNJ/PX45MX9J47ecP8876zX7yXF3O/bNzuUEXFs17jPpqECpIQKTX1GYumVHr/bqbs4sHyGxRnjFYtoYmQ8AqvXTheyUNUu5ktqeRTp/O9KU6DrOnbgdnptkbuVuM/PrGh0+Dvi1s8WTWE+A4RQintTHM9eGJXOD2ztAne1XBL0Sjy6TSkeLDiP5yEd1k0rdEietVrDmAqqW/BEap/90Ypas8EH0Xb8LJ7y6f9TnZUwzu6HyAB8gsWyZXCrQDzCVpS7eQj60df3BSuPPfRzn2kSDh+Qs/V2zzrwoNNxP2fksYNzNudNW/O7AZ9/+sZaC+iSSm99NQqif7IKi7MWMNlmcQ9l25Oocup+PJfhvuq1pBeMlfYetNPZHKG8j34TXXAhn0CSkuIjqqpyrDpQyJpDKNSlWSLtrijYaRu0C9iPqx40SE9+hU30Ay0noyfx1t3SeG7OTCUyVt4ZyRNnfbuwgKnv/tY1yayE7YXEzj1gNuuaaCdYbh8dOKtoX8UbwvaGdu2jvu1MOlr43wlq/csnh/6TK9KrYpCCFEOxWePPeMiDx7pQgMZ1P4zC8+B8Z11ucUp6Jhqh8pIS5UBE2LyrJa/wA1Wt5iZxSHprs1YF+KrciyF8HYxKyI=

.utility/initiate-publish.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
# This script initiates the Gradle publishing task when pushes to master occur.
3+
# NOTE: Travis-CI can only publish SNAPSHOT versions. To release a version, you need
4+
# to use the internal Jenkins job.
5+
6+
echo Repo: $TRAVIS_REPO_SLUG Pull Request: $TRAVIS_PULL_REQUEST Branch: $TRAVIS_BRANCH
7+
if [ "$TRAVIS_PULL_REQUEST" == "false" ] && [ "$TRAVIS_BRANCH" == "master" ]; then
8+
export GIT_COUNT=`git rev-list HEAD --count`
9+
echo "Starting publish to Sonatype... $GIT_COUNT"
10+
11+
./gradlew uploadArchives -PNEXUS_USERNAME=${SONATYPE_USERNAME} -PNEXUS_PASSWORD=${SONATYPE_PASSWORD}
12+
RETVAL=$?
13+
14+
if [ $RETVAL -eq 0 ]; then
15+
echo 'Completed publish!'
16+
else
17+
echo 'Publish failed.'
18+
return 1
19+
fi
20+
21+
fi

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
# UtilsVerifier
22
UtilsVerifier is a pure java library that can be used in junit tests to verify that Utility method is properly defined.
33

4-
Check by default includes:
4+
[![Build Status](https://travis-ci.org/karczews/UtilsVerifier.svg?branch=master)](https://travis-ci.org/karczews/UtilsVerifier)
5+
[![codecov](https://codecov.io/gh/karczews/UtilsVerifier/branch/master/graph/badge.svg)](https://codecov.io/gh/karczews/UtilsVerifier)
6+
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/com.github.karczews/utilsverifier.svg?style=flat)](https://oss.sonatype.org/content/repositories/snapshots/com/github/karczews/utilsverifier/)
7+
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/karczews/UtilsVerifier/blob/master/LICENSE)
8+
9+
By default verification includes:
510
* private constructor check
611
* class is final
712
* class has no instance fields

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ allprojects {
1818
}
1919

2020
apply plugin: "java-library"
21+
apply plugin: "jacoco"
22+
apply from: 'gradle-mvn-push.gradle'
2123

2224
sourceCompatibility = JavaVersion.VERSION_1_5
2325
targetCompatibility = JavaVersion.VERSION_1_5
@@ -26,3 +28,11 @@ dependencies {
2628
testImplementation deps.junit
2729
testImplementation deps.mockitocore
2830
}
31+
32+
jacocoTestReport {
33+
reports {
34+
xml.enabled true
35+
csv.enabled false
36+
html.enabled true
37+
}
38+
}

gradle-mvn-push.gradle

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -92,29 +92,28 @@ afterEvaluate { project ->
9292
sign configurations.archives
9393
}
9494

95-
task androidJavadocs(type: Javadoc) {
96-
source = android.sourceSets.main.java.srcDirs
97-
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
98-
classpath += configurations.compile
95+
javadoc {
96+
source = sourceSets.main.allJava
97+
classpath = configurations.compileClasspath
98+
9999
options {
100-
options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PUBLIC
101-
linksOffline "http://d.android.com/reference", "${android.sdkDirectory}/docs/reference"
102-
links "http://reactivex.io/RxJava/javadoc"
100+
setMemberLevel JavadocMemberLevel.PUBLIC
101+
links "https://docs.oracle.com/javase/8/docs/api/"
103102
}
104103
}
105104

106-
task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
105+
task javadocsJar(type: Jar, dependsOn: javadoc) {
107106
classifier = 'javadoc'
108-
from androidJavadocs.destinationDir
107+
from javadoc.destinationDir
109108
}
110109

111-
task androidSourcesJar(type: Jar) {
110+
task sourcesJar(type: Jar) {
112111
classifier = 'sources'
113-
from android.sourceSets.main.java.sourceFiles
112+
from sourceSets.main.allJava
114113
}
115114

116115
artifacts {
117-
archives androidSourcesJar
118-
archives androidJavadocsJar
116+
archives javadocsJar
117+
archives sourcesJar
119118
}
120119
}

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

Lines changed: 70 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
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
import java.lang.reflect.Constructor;
416
import java.lang.reflect.Field;
517
import java.lang.reflect.InvocationTargetException;
618
import java.lang.reflect.Modifier;
719

20+
/**
21+
* {@code EqualsVerifier} tool can be used in unit tests to verify if certain util class is
22+
* well formed.
23+
* <p>
24+
* By default verifier performs following checks that class:
25+
* <ul>
26+
* <li> is final
27+
* <li> has only one private constructor
28+
* <li> has no instance fields
29+
* </ul>
30+
*
31+
* @param <T> class under test
32+
*/
833
public class UtilsVerifier<T> {
934

1035
private final Class<T> classUnderTest;
@@ -20,48 +45,78 @@ private UtilsVerifier(final Class<T> type) {
2045
}
2146

2247
/**
23-
* Creates UtilsVerifier for provided type.
48+
* Creates UtilsVerifier instance for provided type.
49+
*
50+
* @param type class type for which verifier will be created
2451
*/
2552
public static <T> UtilsVerifier<T> forClass(final Class<T> type) {
2653
return new UtilsVerifier<T>(type);
2754
}
2855

56+
/**
57+
* Performs verification for provided type.
58+
* {@link AssertionError} will be thrown if provided type is not well formed util class.
59+
*/
60+
public void verify() {
61+
checkIfClassIsFinal();
62+
hasOnlyOneConstructor();
63+
verifyPrivateConstructor();
64+
hasNoInstanceFields();
65+
}
66+
67+
/**
68+
* Sets exception type that will be expected during construction attempt.
69+
*
70+
* @param type expected exception type
71+
*/
2972
public UtilsVerifier<T> withConstructorThrowing(final Class<? extends Throwable> type) {
3073
expectedConstructorException = type;
3174
return this;
3275
}
3376

77+
/**
78+
* Suppress final class verification. Use if non-final util class is allowed.
79+
*
80+
* @param suppressCheck true if check should be suppressed, false otherwise
81+
*/
3482
public UtilsVerifier<T> suppressFinalClassCheck(final boolean suppressCheck) {
3583
suppressFinalClassCheck = suppressCheck;
3684
return this;
3785
}
3886

87+
/**
88+
* Suppress single constructor verification.
89+
* Use if util class is allowed to have more than one constructor.
90+
*
91+
* @param suppressCheck true if check should be suppressed, false otherwise
92+
*/
3993
public UtilsVerifier<T> suppressOnlyOneConstructorCheck(final boolean suppressCheck) {
4094
suppressOnlyOneConstructorCheck = suppressCheck;
4195
return this;
4296
}
4397

98+
/**
99+
* Suppress private constructor verification.
100+
* Use if util class is allowed to have non private constructor.
101+
*
102+
* @param suppressCheck true if check should be suppressed, false otherwise
103+
*/
44104
public UtilsVerifier<T> suppressPrivateConstructorCheck(final boolean suppressCheck) {
45105
suppressPrivateConstructorCheck = suppressCheck;
46106
return this;
47107
}
48108

109+
/**
110+
* Suppress instance field verification.
111+
* Use if util class is allowed to have instance fields.
112+
*
113+
* @param suppressCheck true if check should be suppressed, false otherwise
114+
*/
49115
public UtilsVerifier<T> suppressInstanceFieldCheck(final boolean suppressCheck) {
50116
suppressInstanceFieldCheck = suppressCheck;
51117
return this;
52118
}
53119

54-
/**
55-
* Performs verification for provided type.
56-
* {@link AssertionError} will be thrown if provided type is not well formed util class.
57-
*/
58-
public void verify() {
59-
checkIfClassIsFinal();
60-
hasOnlyOneConstructor();
61-
verifyPrivateConstructor();
62-
hasNoInstanceFields();
63-
}
64-
65120
private void checkIfClassIsFinal() {
66121
if (suppressFinalClassCheck) return;
67122
if (!Modifier.isFinal(classUnderTest.getModifiers())) {
@@ -93,15 +148,13 @@ private void verifyPrivateConstructor() {
93148
if (expectedConstructorException != null) {
94149
throw new AssertionError("should not be able to instantiate " + classUnderTest.getSimpleName());
95150
}
96-
} catch (final IllegalAccessException e) {
97-
throw new IllegalStateException(e);
98-
} catch (final InstantiationException e) {
99-
throw new IllegalStateException(e);
100151
} catch (final InvocationTargetException e) {
101152
if (!expectedConstructorException.isInstance(e.getTargetException())) {
102153
throw new AssertionError("expected exception: " + expectedConstructorException.getName() +
103154
" got: " + e.getTargetException().getClass().getName());
104155
}
156+
} catch (final ReflectiveOperationException e) {
157+
throw new IllegalStateException(e);
105158
}
106159
}
107160

@@ -115,5 +168,6 @@ private void hasNoInstanceFields() {
115168
}
116169
}
117170
}
171+
//TODO: add check for non-static methods
118172
//TODO: add check for mutable static fields
119173
}

src/test/java/com/github/karczews/utilsverifier/UtilsVerifierTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
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

416
import com.github.karczews.utilsverifier.subjects.InstanceFields;
517
import com.github.karczews.utilsverifier.subjects.MultipleConstructors;
618
import com.github.karczews.utilsverifier.subjects.NonFinalClass;
7-
import com.github.karczews.utilsverifier.subjects.ThrowingConstuctor;
19+
import com.github.karczews.utilsverifier.subjects.ThrowingConstructor;
820
import com.github.karczews.utilsverifier.subjects.WellFormed;
921

1022
import org.junit.Rule;
@@ -66,14 +78,14 @@ public void shouldFailWhenExpectingDifferentException() {
6678
containsString("IllegalStateException"),
6779
containsString("IllegalArgumentException")));
6880

69-
suppressedVerifier(ThrowingConstuctor.class)
81+
suppressedVerifier(ThrowingConstructor.class)
7082
.withConstructorThrowing(IllegalArgumentException.class)
7183
.verify();
7284
}
7385

7486
@Test
7587
public void shouldPassWhenExpectedExceptionReceived() {
76-
suppressedVerifier(ThrowingConstuctor.class)
88+
suppressedVerifier(ThrowingConstructor.class)
7789
.withConstructorThrowing(IllegalStateException.class)
7890
.verify();
7991
}

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1-
package com.github.karczews.utilsverifier.subjects;
2-
31
/**
4-
* Created by karczews on 10.12.17.
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.
512
*/
13+
package com.github.karczews.utilsverifier.subjects;
614

715
public final class InstanceFields {
816
private int instanceInt;

src/test/java/com/github/karczews/utilsverifier/subjects/MultipleConstructors.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 MultipleConstructors {

src/test/java/com/github/karczews/utilsverifier/subjects/NonFinalClass.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 class NonFinalClass {

0 commit comments

Comments
 (0)