Skip to content

Fixing numberformatExceptions for European countries #47

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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