Skip to content

Commit

Permalink
Solving locale issue upstream by adding locale variable
Browse files Browse the repository at this point in the history
  • Loading branch information
NullStress committed Nov 14, 2015
1 parent 47681d9 commit 9318c5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
6 changes: 5 additions & 1 deletion src/main/groovy/org/scoverage/OverallCheckTask.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ class OverallCheckTask extends DefaultTask {
/** Set if want to change default from 'reportDir' in scoverage extension. */
File reportDir

/** Overwrite to test for a specific locale. */
Locale locale

protected XmlParser parser

protected DecimalFormat df = new DecimalFormat("#.##")

OverallCheckTask() {
Expand All @@ -73,7 +77,7 @@ class OverallCheckTask extends DefaultTask {

try {
Node xml = parser.parse(reportFile)
NumberFormat nf = NumberFormat.getInstance();
NumberFormat nf = NumberFormat.getInstance(locale == null ? Locale.getDefault() : locale);
Double coverageValue = nf.parse(xml.attribute(coverageType.paramName) as String).doubleValue();
Double overallRate = coverageType.normalize(coverageValue)
def difference = (minimumRate - overallRate)
Expand Down
19 changes: 7 additions & 12 deletions src/test/groovy/org/scoverage/OverallCheckTaskTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import org.junit.Rule
import org.junit.Test
import org.junit.rules.ExpectedException

import javax.swing.text.NumberFormatter
import java.text.NumberFormat

/**
* Copied from the Internet, just to check if we have correct exception thrown.
*/
Expand Down Expand Up @@ -41,17 +44,6 @@ 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 All @@ -60,6 +52,7 @@ class OverallCheckTaskTest {
Project project = ProjectBuilder.builder().build()
project.plugins.apply(ScoveragePlugin)
project.tasks.create('bob', OverallCheckTask) {
locale = Locale.US
minimumRate = coverageRate
reportDir = new File('src/test/resources')
coverageType = type
Expand All @@ -74,6 +67,7 @@ class OverallCheckTaskTest {
Project project = ProjectBuilder.builder().build()
project.plugins.apply(ScoveragePlugin)
project.tasks.create('bob', OverallCheckTask) {
locale = Locale.US
minimumRate = 1.0
reportDir = new File('src/test/nothingthere')
coverageType = CoverageType.Line
Expand Down Expand Up @@ -114,9 +108,10 @@ class OverallCheckTaskTest {
@Test
void failsWhenStatementRateIsBelowTarget() {
Project project = projectForRate(1, CoverageType.Statement)
NumberFormat nf = NumberFormat.getInstance()
expectedException.expectCause(new CauseMatcher(
GradleException.class,
OverallCheckTask.errorMsg("33.33", "100", CoverageType.Statement)
OverallCheckTask.errorMsg(nf.format(new Double(33.33)), "100", CoverageType.Statement)
))
project.tasks.bob.execute()
}
Expand Down

0 comments on commit 9318c5c

Please sign in to comment.