Skip to content

Commit

Permalink
Merge pull request #50 from NullStress/master
Browse files Browse the repository at this point in the history
Adding locale upstream
  • Loading branch information
maiflai committed Nov 23, 2015
2 parents c12b7fa + 9318c5c commit 9e474a9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 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(Locale.getDefault());
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
2 changes: 1 addition & 1 deletion src/test/groovy/org/scoverage/AcceptanceTestUtils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AcceptanceTestUtils {
File reportFile = new File(reportDir, coverageType.fileName)
def xml = parser.parse(reportFile)
println("reportfile path: ${reportFile.absolutePath}")
NumberFormat nf = NumberFormat.getInstance(Locale.getDefault());
NumberFormat nf = NumberFormat.getInstance();
nf.parse(xml.attribute(coverageType.paramName) as String).doubleValue();
}
}
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 9e474a9

Please sign in to comment.