Skip to content

Commit

Permalink
Merge pull request #47 from NullStress/master
Browse files Browse the repository at this point in the history
Fixing numberformatExceptions for European countries
  • Loading branch information
sksamuel committed Nov 9, 2015
2 parents 042d38a + c019e35 commit c12b7fa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/main/groovy/org/scoverage/OverallCheckTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.gradle.api.GradleException
import org.gradle.api.tasks.TaskAction

import java.text.DecimalFormat
import java.text.NumberFormat

/**
* Handles different types of coverage Scoverage can measure.
Expand Down Expand Up @@ -71,8 +72,10 @@ class OverallCheckTask extends DefaultTask {
File reportFile = new File(reportDir ? reportDir : extension.reportDir, coverageType.fileName)

try {
def xml = parser.parse(reportFile)
Double overallRate = coverageType.normalize(xml.attribute(coverageType.paramName).toDouble())
Node xml = parser.parse(reportFile)
NumberFormat nf = NumberFormat.getInstance(Locale.getDefault());
Double coverageValue = nf.parse(xml.attribute(coverageType.paramName) as String).doubleValue();
Double overallRate = coverageType.normalize(coverageValue)
def difference = (minimumRate - overallRate)

if (difference > 1e-7) {
Expand Down
6 changes: 5 additions & 1 deletion src/test/groovy/org/scoverage/AcceptanceTestUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.gradle.tooling.GradleConnector
import org.hamcrest.core.Is
import org.junit.Assert

import java.text.NumberFormat

/**
* Some utils for easy acceptance testing.
*/
Expand Down Expand Up @@ -38,6 +40,8 @@ class AcceptanceTestUtils {
protected Double coverage(File reportDir, CoverageType coverageType) {
File reportFile = new File(reportDir, coverageType.fileName)
def xml = parser.parse(reportFile)
xml.attribute(coverageType.paramName).toDouble()
println("reportfile path: ${reportFile.absolutePath}")
NumberFormat nf = NumberFormat.getInstance(Locale.getDefault());
nf.parse(xml.attribute(coverageType.paramName) as String).doubleValue();
}
}
15 changes: 15 additions & 0 deletions src/test/groovy/org/scoverage/OverallCheckTaskTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import org.gradle.api.Project
import org.gradle.testfixtures.ProjectBuilder
import org.hamcrest.Description
import org.hamcrest.TypeSafeMatcher
import org.junit.After
import org.junit.AfterClass
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException
Expand Down Expand Up @@ -37,6 +41,17 @@ class CauseMatcher extends TypeSafeMatcher<Throwable> {
}

class OverallCheckTaskTest {
private static Locale defaultLocale
@BeforeClass
public static void setup() {
defaultLocale = Locale.getDefault()
Locale.setDefault(Locale.US)
}

@AfterClass
public static void tearDown() {
Locale.setDefault(defaultLocale)
}

@Rule
public ExpectedException expectedException = ExpectedException.none()
Expand Down

0 comments on commit c12b7fa

Please sign in to comment.