Skip to content

Simplifying since Locale.getDefault() is used by default #48

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

Closed
wants to merge 2 commits into from
Closed
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
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