Skip to content

Commit

Permalink
Merge pull request #14 from rkluszczynski/increaseCodeCoverage
Browse files Browse the repository at this point in the history
increase coverage
  • Loading branch information
rkluszczynski committed Feb 8, 2017
2 parents 79f29d5 + 821a25c commit 90ac7fb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 28 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {

id 'checkstyle'
id 'jacoco'
id 'com.github.kt3k.coveralls' version '2.7.1'
id 'com.github.kt3k.coveralls' version '2.8.1'

id 'org.springframework.boot' version '1.5.1.RELEASE'
id 'pl.allegro.tech.build.axion-release' version '1.5.0'
Expand All @@ -30,7 +30,7 @@ targetCompatibility = 1.8

def versions = [
avro : '1.8.1',
spock : '1.0-groovy-2.4',
spock : '1.1-groovy-2.4-rc-3',

checkstyle: '6.3',
gradle : '3.3'
Expand All @@ -42,7 +42,7 @@ dependencies {
'com.beust:jcommander:1.58',
'tech.allegro.schema.json2avro:converter:0.2.5'

testCompile 'com.github.tomakehurst:wiremock:2.5.0',
testCompile 'com.github.tomakehurst:wiremock:2.5.1',
'cglib:cglib-nodep:3.2.4',
'org.objenesis:objenesis:2.5.1',
"org.spockframework:spock-core:${versions.spock}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,39 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.ApplicationContext
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification
import spock.lang.Unroll

import static java.util.Objects.nonNull

@ContextConfiguration
@SpringBootTest
class AvroCliApplicationTest extends Specification {

class AvroCliApplicationTest extends BaseTestSpecification {
@Autowired
ApplicationContext context

def 'should boot up without errors'() {
expect:
nonNull(context)
}

def 'should show exception when verbose main parameter exists'() {
when:
AvroCliApplication.main('-v', 'validate')

then:
trimmedOutput().startsWith('FAILED [com.beust.jcommander.ParameterException] ')
trimmedOutput().contains('\ncom.beust.jcommander.ParameterException: ')
}

@Unroll
'should show help for command: #command'() {
when:
AvroCliApplication.main(command, '-h')

then:
trimmedOutput().contains('\nUsage: ' + command + ' [options]\n Options:\n')

where:
command << ['convert', 'validate']
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.rkluszczynski.avro.cli

import org.junit.Rule
import org.springframework.boot.test.rule.OutputCapture
import spock.lang.Specification

abstract class BaseTestSpecification extends Specification {
@Rule
OutputCapture capture = new OutputCapture()

protected trimmedOutput() {
capture.toString().trim()
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package io.github.rkluszczynski.avro.cli.command

import io.github.rkluszczynski.avro.cli.BaseTestSpecification
import io.github.rkluszczynski.avro.cli.CliCommandService
import io.github.rkluszczynski.avro.cli.command.conversion.AvroConversion
import io.github.rkluszczynski.avro.cli.command.conversion.ConversionService
import org.junit.Rule
import org.springframework.boot.test.rule.OutputCapture
import spock.lang.Specification

class ConversionCommandTest extends Specification {
class ConversionCommandTest extends BaseTestSpecification {
private commandService = new CliCommandService([new AvroConversion(new ConversionService())])

@Rule
OutputCapture capture = new OutputCapture()

def 'should pass friendly conversion from json to avro'() {
given:
def tmpFile = File.createTempFile('message', '.avro')
Expand Down Expand Up @@ -85,10 +80,6 @@ class ConversionCommandTest extends Specification {
trimmedOutput() == 'FAILED [io.github.rkluszczynski.avro.cli.CommandException] Exactly one of target format should be indicated (Avro or JSON).'
}

private trimmedOutput() {
capture.toString().trim()
}

private prepareFilePath(filename) {
"src/test/resources/conversion/${filename}"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
package io.github.rkluszczynski.avro.cli.command

import io.github.rkluszczynski.avro.cli.BaseTestSpecification
import io.github.rkluszczynski.avro.cli.CliCommandService
import io.github.rkluszczynski.avro.cli.command.validation.AvroNativeValidation
import org.junit.Rule
import org.springframework.boot.test.rule.OutputCapture
import spock.lang.Specification
import spock.lang.Unroll

class ValidationCommandTest extends Specification {
class ValidationCommandTest extends BaseTestSpecification {
private commandService = new CliCommandService([new AvroNativeValidation()])

@Rule
OutputCapture capture = new OutputCapture()

@Unroll
'should pass validation for #compatibilityStrategy'() {
when:
Expand Down Expand Up @@ -52,10 +47,6 @@ class ValidationCommandTest extends Specification {
trimmedOutput().endsWith('not-existing-file.avsc (No such file or directory)')
}

private trimmedOutput() {
capture.toString().trim()
}

private prepareSchemaValidationPath(schemaFilename) {
"src/test/resources/validation/${schemaFilename}"
}
Expand Down

0 comments on commit 90ac7fb

Please sign in to comment.