Skip to content

Commit

Permalink
Use JUnit Pioneer instead of direct global variables access
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Dec 26, 2024
1 parent 97bd5ec commit 48e7dd8
Showing 1 changed file with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import java.text.NumberFormat;
import java.util.Locale;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultLocale;

/**
* Test Case for CurrencyValidator.
Expand All @@ -39,20 +39,12 @@ public class CurrencyValidatorTest {
private String usDollar;
private String ukPound;

private Locale originalLocale;

@BeforeEach
protected void setUp() {
originalLocale = Locale.getDefault();
usDollar = new DecimalFormatSymbols(Locale.US).getCurrencySymbol();
ukPound = new DecimalFormatSymbols(Locale.UK).getCurrencySymbol();
}

@AfterEach
protected void tearDown() {
Locale.setDefault(originalLocale);
}

/**
* Test Format Type
*/
Expand Down Expand Up @@ -82,10 +74,8 @@ public void testIntegerInvalid() {
* Test Valid integer (non-decimal) currency values
*/
@Test
@DefaultLocale("en-GB")
public void testIntegerValid() {
// Set the default Locale
Locale.setDefault(Locale.UK);

final CurrencyValidator validator = new CurrencyValidator();
final BigDecimal expected = new BigDecimal("1234.00");
final BigDecimal negative = new BigDecimal("-1234.00");
Expand Down Expand Up @@ -143,10 +133,8 @@ public void testInvalid() {
* Test currency values with a pattern
*/
@Test
@DefaultLocale("en-GB")
public void testPattern() {
// Set the default Locale
Locale.setDefault(Locale.UK);

final BigDecimalValidator validator = CurrencyValidator.getInstance();
final String basicPattern = CURRENCY_SYMBOL + "#,##0.000";
final String pattern = basicPattern + ";[" + basicPattern + "]";
Expand Down Expand Up @@ -174,10 +162,8 @@ public void testPattern() {
* Test Valid currency values
*/
@Test
@DefaultLocale("en-GB")
public void testValid() {
// Set the default Locale
Locale.setDefault(Locale.UK);

final BigDecimalValidator validator = CurrencyValidator.getInstance();
final BigDecimal expected = new BigDecimal("1234.56");
final BigDecimal negative = new BigDecimal("-1234.56");
Expand Down

0 comments on commit 48e7dd8

Please sign in to comment.