Code coverage w. JaCoCo.

This commit is contained in:
Mark Nellemann 2019-08-23 08:18:13 +02:00
parent 9df016a5f4
commit 231c0e7ac0
24 changed files with 3027 additions and 71 deletions

View file

@ -4,6 +4,7 @@ buildscript {
}
dependencies {
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
//classpath 'com.bmuschko:gradle-clover-plugin:2.2.3'
}
}
@ -11,8 +12,14 @@ apply plugin: "idea"
apply plugin: "java"
apply plugin: "groovy"
apply plugin: 'maven'
apply plugin: 'jacoco'
apply plugin: 'maven-publish'
apply plugin: 'com.jfrog.bintray'
//apply from: "${project.projectDir}/gradle/clover.gradle"
version = "${version}-SNAPSHOT"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
@ -21,11 +28,12 @@ repositories {
dependencies {
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
//implementation("org.slf4j:slf4j-simple:${slf4jVersion}")
implementation('com.google.code.gson:gson:2.8.5')
implementation("com.squareup.okhttp3:okhttp:4.1.0")
testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}")
testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}")
testImplementation('com.squareup.okhttp3:mockwebserver:4.1.0')
testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}")
testCompile("org.spockframework:spock-core:${spockVersion}") {
exclude group: "org.codehaus.groovy"
}
@ -60,3 +68,39 @@ bintray {
publish = true
}
}
jacoco {
toolVersion = "0.8.4"
}
jacocoTestReport {
group = "verification"
reports {
xml.enabled false
csv.enabled false
html.destination file("${buildDir}/reports/coverage")
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: 'biz/nellemann/libcvrapi/pojo/**')
}))
}
}
test.finalizedBy jacocoTestReport
jacocoTestCoverageVerification {
violationRules {
rule {
element = 'CLASS'
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.5
}
excludes = [
'biz.nellemann.libcvrapi.pojo.*'
]
}
}
}
check.dependsOn jacocoTestCoverageVerification

View file

@ -1,6 +1,6 @@
id = libcvrapi
group = biz.nellemann.libs
version = 1.0.1
version = 1.0.2
licenses = ['APACHE-2.0'] // or something else
groovyVersion = 2.5.8
slf4jVersion = 1.7.28

63
gradle/clover.gradle Normal file
View file

@ -0,0 +1,63 @@
apply plugin: 'com.bmuschko.clover'
dependencies {
clover 'org.openclover:clover:4.3.1'
}
clover {
excludes = ['**/SynchronizedMultiValueMap.java']
// This is the default testIncludes configuration
testIncludes = ['**/*Test.java', '**/*Spec.groovy']
testExcludes = ['**/Mock*.java']
targetPercentage = '85%'
report {
html = true
pdf = true
filter = 'log,main,getters,setters'
// Support capturing test results from JUnix XML report
testResultsDir = project.tasks.getByName('test').reports.junitXml.destination
testResultsInclude = 'TEST-*.xml'
// Clover report nested columns support
columns {
coveredMethods format: 'longbar', min: '75'
coveredStatements format: '%'
coveredBranches format: 'raw'
totalPercentageCovered format: '%', scope: 'package'
}
// Clover history generation support
// See Clover documentation for details of the values supported
historical {
enabled = true
historyIncludes = 'clover-*.xml.gz'
packageFilter = null
from = null
to = null
added {
range = 10
interval = '3 weeks'
}
mover {
threshold = 1
range = 10
interval = '3 weeks'
}
mover {
threshold = 1
range = 10
interval = '3 months'
}
mover {
threshold = 1
range = 10
interval = '1 year'
}
}
}
}

View file

@ -21,6 +21,7 @@ package biz.nellemann.libcvrapi;
import java.io.IOException;
import biz.nellemann.libcvrapi.pojo.Company;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
@ -77,6 +78,7 @@ public class CvrApi {
*/
protected String getCompanyJson(String vatNumber) throws IOException, Exception {
String response = get("https://rest.cvrapi.dk/v1/dk/company/" + vatNumber);
log.debug("getCompanyJson() response: " + response);
return response;
}

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
import java.util.List;

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class AccountingDocument {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
import java.math.BigDecimal;

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Address {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Capital {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
import java.math.BigDecimal;
import java.util.ArrayList;

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Companyform {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Companystatus {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Contact {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Industrycode {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Info {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class InfoEmployment {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Life {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Shareholder {

View file

@ -17,7 +17,7 @@
* under the License.
*/
package biz.nellemann.libcvrapi;
package biz.nellemann.libcvrapi.pojo;
public class Status {

View file

@ -1,20 +0,0 @@
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<logger name="biz.nellemann.libcvrapi" level="debug" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<root level="error">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>

View file

@ -5,21 +5,19 @@ import spock.lang.Specification
class CvrApiSpec extends Specification {
CvrApi api
File testFile
String testJson
def setup() {
api = new CvrApi("Test User Agent", "testAuthToken")
testFile = new File(getClass().getResource('/company.json').toURI())
testJson = testFile.getText('UTF-8')
}
def cleanup() { }
void "test we can parse a company"() {
void "test we can parse company with CVR 25063864"() {
when:
def company = api.parseJsonIntoCompany(testJson)
def testFile = new File(getClass().getResource('/25063864.json').toURI())
def testJson = testFile.getText('UTF-8')
def company = api.parseJsonIntoCompany(testJson)
then:
company != null
@ -30,5 +28,23 @@ class CvrApiSpec extends Specification {
company.info.employment.amountEmployeesHigh == 99
}
void "test we can parse company with CVR 15027800"() {
when:
def testFile = new File(getClass().getResource('/15027800.json').toURI())
def testJson = testFile.getText('UTF-8')
def company = api.parseJsonIntoCompany(testJson)
then:
company != null
company.vat == 15027800
company.life.name == 'FREJA TRANSPORT & LOGISTICS A/S'
company.secondarynames.contains('KT TRANSPORT A/S')
company.info.employment.amountEmployeesLow == 200
company.info.employment.amountEmployeesHigh == 499
}
// TODO: Get better code coverage in tests, eg. by mocking okHttp interface - but how ?
}

File diff suppressed because it is too large Load diff

View file

@ -1,21 +0,0 @@
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<layout class="ch.qos.logback.classic.PatternLayout">
<Pattern>
%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n
</Pattern>
</layout>
</appender>
<logger name="biz.nellemann.libcvrapi" level="debug" additivity="false">
<appender-ref ref="CONSOLE"/>
</logger>
<root level="error">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>