You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2020/05/10 15:24:01 UTC

[commons-validator] branch master updated: Ensure defaults are restored even if test fails

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-validator.git


The following commit(s) were added to refs/heads/master by this push:
     new bda3c63  Ensure defaults are restored even if test fails
bda3c63 is described below

commit bda3c63b7c15301c5e2a3bbcb29ba28a8355c30f
Author: Sebb <se...@apache.org>
AuthorDate: Sun May 10 16:23:48 2020 +0100

    Ensure defaults are restored even if test fails
---
 .../commons/validator/routines/TimeValidatorTest.java     | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java
index f9399be..aabc942 100644
--- a/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/TimeValidatorTest.java
@@ -94,6 +94,9 @@ public class TimeValidatorTest extends TestCase {
                         ,"10::1"    // invalid pattern
                         ,"10:1:"};  // invalid pattern
 
+    private Locale origDefault;
+    private TimeZone defaultZone;
+
     /**
      * Constructor
      * @param name test name
@@ -106,6 +109,8 @@ public class TimeValidatorTest extends TestCase {
     protected void setUp() throws Exception {
         super.setUp();
         validator = new TimeValidator();
+        defaultZone = TimeZone.getDefault();
+        origDefault = Locale.getDefault();
     }
 
     /**
@@ -116,6 +121,8 @@ public class TimeValidatorTest extends TestCase {
     protected void tearDown() throws Exception {
         super.tearDown();
         validator = null;
+        Locale.setDefault(origDefault);
+        TimeZone.setDefault(defaultZone);
     }
 
     /**
@@ -175,9 +182,7 @@ public class TimeValidatorTest extends TestCase {
      */
     public void testTimeZone() {
         // Set the default Locale & TimeZone
-        Locale origDefault = Locale.getDefault();
         Locale.setDefault(Locale.UK);
-        TimeZone defaultZone = TimeZone.getDefault();
         TimeZone.setDefault(GMT);
 
         Calendar result = null;
@@ -236,9 +241,6 @@ public class TimeValidatorTest extends TestCase {
         assertEquals("pattern minute", 05, result.get(Calendar.MINUTE));
         result = null;
 
-        // Restore the original default
-        Locale.setDefault(origDefault);
-        TimeZone.setDefault(defaultZone);
     }
 
     /**
@@ -246,7 +248,6 @@ public class TimeValidatorTest extends TestCase {
      */
     public void testFormat() {
         // Set the default Locale
-        Locale origDefault = Locale.getDefault();
         Locale.setDefault(Locale.UK);
 
         Object test = TimeValidator.getInstance().validate("16:49:23", "HH:mm:ss");
@@ -255,8 +256,6 @@ public class TimeValidatorTest extends TestCase {
         assertEquals("Format locale",  "4:49 PM",  validator.format(test, Locale.US));
         assertEquals("Format default", "16:49",  validator.format(test));
 
-        // Restore the original default
-        Locale.setDefault(origDefault);
     }
 
     /**