Code coverage w. JaCoCo.
This commit is contained in:
parent
9df016a5f4
commit
231c0e7ac0
46
build.gradle
46
build.gradle
|
@ -4,6 +4,7 @@ buildscript {
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
|
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: "java"
|
||||||
apply plugin: "groovy"
|
apply plugin: "groovy"
|
||||||
apply plugin: 'maven'
|
apply plugin: 'maven'
|
||||||
|
apply plugin: 'jacoco'
|
||||||
apply plugin: 'maven-publish'
|
apply plugin: 'maven-publish'
|
||||||
apply plugin: 'com.jfrog.bintray'
|
apply plugin: 'com.jfrog.bintray'
|
||||||
|
//apply from: "${project.projectDir}/gradle/clover.gradle"
|
||||||
|
|
||||||
|
version = "${version}-SNAPSHOT"
|
||||||
|
sourceCompatibility = 1.8
|
||||||
|
targetCompatibility = 1.8
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -21,10 +28,11 @@ repositories {
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
|
implementation("org.slf4j:slf4j-api:${slf4jVersion}")
|
||||||
//implementation("org.slf4j:slf4j-simple:${slf4jVersion}")
|
|
||||||
implementation('com.google.code.gson:gson:2.8.5')
|
implementation('com.google.code.gson:gson:2.8.5')
|
||||||
implementation("com.squareup.okhttp3:okhttp:4.1.0")
|
implementation("com.squareup.okhttp3:okhttp:4.1.0")
|
||||||
|
|
||||||
|
testImplementation("org.slf4j:slf4j-simple:${slf4jVersion}")
|
||||||
|
testImplementation('com.squareup.okhttp3:mockwebserver:4.1.0')
|
||||||
testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}")
|
testCompile("org.codehaus.groovy:groovy-all:${groovyVersion}")
|
||||||
testCompile("org.spockframework:spock-core:${spockVersion}") {
|
testCompile("org.spockframework:spock-core:${spockVersion}") {
|
||||||
exclude group: "org.codehaus.groovy"
|
exclude group: "org.codehaus.groovy"
|
||||||
|
@ -60,3 +68,39 @@ bintray {
|
||||||
publish = true
|
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
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
id = libcvrapi
|
id = libcvrapi
|
||||||
group = biz.nellemann.libs
|
group = biz.nellemann.libs
|
||||||
version = 1.0.1
|
version = 1.0.2
|
||||||
licenses = ['APACHE-2.0'] // or something else
|
licenses = ['APACHE-2.0'] // or something else
|
||||||
groovyVersion = 2.5.8
|
groovyVersion = 2.5.8
|
||||||
slf4jVersion = 1.7.28
|
slf4jVersion = 1.7.28
|
||||||
|
|
63
gradle/clover.gradle
Normal file
63
gradle/clover.gradle
Normal 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'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ package biz.nellemann.libcvrapi;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import biz.nellemann.libcvrapi.pojo.Company;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
|
@ -77,6 +78,7 @@ public class CvrApi {
|
||||||
*/
|
*/
|
||||||
protected String getCompanyJson(String vatNumber) throws IOException, Exception {
|
protected String getCompanyJson(String vatNumber) throws IOException, Exception {
|
||||||
String response = get("https://rest.cvrapi.dk/v1/dk/company/" + vatNumber);
|
String response = get("https://rest.cvrapi.dk/v1/dk/company/" + vatNumber);
|
||||||
|
log.debug("getCompanyJson() response: " + response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class AccountingDocument {
|
public class AccountingDocument {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Address {
|
public class Address {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Capital {
|
public class Capital {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Companyform {
|
public class Companyform {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Companystatus {
|
public class Companystatus {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Contact {
|
public class Contact {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Industrycode {
|
public class Industrycode {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Info {
|
public class Info {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class InfoEmployment {
|
public class InfoEmployment {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Life {
|
public class Life {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Shareholder {
|
public class Shareholder {
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package biz.nellemann.libcvrapi;
|
package biz.nellemann.libcvrapi.pojo;
|
||||||
|
|
||||||
public class Status {
|
public class Status {
|
||||||
|
|
|
@ -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>
|
|
||||||
|
|
|
@ -5,20 +5,18 @@ import spock.lang.Specification
|
||||||
class CvrApiSpec extends Specification {
|
class CvrApiSpec extends Specification {
|
||||||
|
|
||||||
CvrApi api
|
CvrApi api
|
||||||
File testFile
|
|
||||||
String testJson
|
|
||||||
|
|
||||||
def setup() {
|
def setup() {
|
||||||
api = new CvrApi("Test User Agent", "testAuthToken")
|
api = new CvrApi("Test User Agent", "testAuthToken")
|
||||||
testFile = new File(getClass().getResource('/company.json').toURI())
|
|
||||||
testJson = testFile.getText('UTF-8')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def cleanup() { }
|
def cleanup() { }
|
||||||
|
|
||||||
void "test we can parse a company"() {
|
void "test we can parse company with CVR 25063864"() {
|
||||||
|
|
||||||
when:
|
when:
|
||||||
|
def testFile = new File(getClass().getResource('/25063864.json').toURI())
|
||||||
|
def testJson = testFile.getText('UTF-8')
|
||||||
def company = api.parseJsonIntoCompany(testJson)
|
def company = api.parseJsonIntoCompany(testJson)
|
||||||
|
|
||||||
then:
|
then:
|
||||||
|
@ -30,5 +28,23 @@ class CvrApiSpec extends Specification {
|
||||||
company.info.employment.amountEmployeesHigh == 99
|
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 ?
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2872
src/test/resources/15027800.json
Normal file
2872
src/test/resources/15027800.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -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>
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue