Add a parent class for locale aware tests

This commit is contained in:
Martin van Wingerden 2019-10-04 10:45:58 +02:00
parent 3d296c30a5
commit 00d903dc6b
No known key found for this signature in database
GPG Key ID: 6DB72288DF1725E3
4 changed files with 27 additions and 11 deletions

View File

@ -0,0 +1,23 @@
package org.baeldung.javaxval;
import java.util.Locale;
import org.junit.AfterClass;
import org.junit.BeforeClass;
public abstract class LocaleAwareUnitTest {
private static Locale previousDefault;
@BeforeClass
public static void setupLocale() {
previousDefault = Locale.getDefault();
Locale.setDefault(Locale.US);
}
@AfterClass
public static void resetLocale() {
Locale.setDefault(previousDefault);
}
}

View File

@ -3,24 +3,22 @@ package org.baeldung.javaxval.bigdecimal;
import static org.assertj.core.api.Assertions.assertThat;
import java.math.BigDecimal;
import java.util.Locale;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import org.baeldung.javaxval.LocaleAwareUnitTest;
import org.junit.BeforeClass;
import org.junit.Test;
public class InvoiceUnitTest {
public class InvoiceUnitTest extends LocaleAwareUnitTest {
private static Validator validator;
@BeforeClass
public static void setupValidatorInstance() {
Locale.setDefault(Locale.US);
validator = Validation.buildDefaultValidatorFactory()
.getValidator();
}

View File

@ -11,9 +11,6 @@ import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import org.baeldung.javaxval.container.validation.Customer;
import org.baeldung.javaxval.container.validation.CustomerMap;
import org.baeldung.javaxval.container.validation.Profile;
import org.baeldung.javaxval.container.validation.valueextractors.ProfileValueExtractor;
import org.junit.Before;
import org.junit.Test;

View File

@ -2,23 +2,21 @@ package org.baeldung.javaxval.validationgroup;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Locale;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import org.baeldung.javaxval.LocaleAwareUnitTest;
import org.junit.BeforeClass;
import org.junit.Test;
public class RegistrationFormUnitTest {
public class RegistrationFormUnitTest extends LocaleAwareUnitTest {
private static Validator validator;
@BeforeClass
public static void setupValidatorInstance() {
Locale.setDefault(Locale.US);
validator = Validation.buildDefaultValidatorFactory()
.getValidator();
}