You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2015/05/07 22:14:42 UTC

[5/8] [lang] Rename SwitchDefaults to SystemDefaultsSwitch to better describe it's role

Rename SwitchDefaults to SystemDefaultsSwitch to better describe it's role


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/bcb33ec1
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/bcb33ec1
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/bcb33ec1

Branch: refs/heads/master
Commit: bcb33ec1c7c4aa98758d1561c8b695737d0a15d5
Parents: 18b3437
Author: Benedikt Ritter <br...@apache.org>
Authored: Thu May 7 20:57:12 2015 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Thu May 7 20:57:12 2015 +0200

----------------------------------------------------------------------
 .../lang3/StringUtilsEqualsIndexOfTest.java     |   4 +-
 .../commons/lang3/test/SwitchDefaults.java      | 113 -------------------
 .../lang3/test/SystemDefaultsSwitch.java        | 113 +++++++++++++++++++
 .../commons/lang3/time/DateFormatUtilsTest.java |   4 +-
 .../commons/lang3/time/DateUtilsTest.java       |   4 +-
 .../commons/lang3/time/FastDateFormatTest.java  |   4 +-
 .../commons/lang3/time/FastDatePrinterTest.java |   6 +-
 7 files changed, 123 insertions(+), 125 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bcb33ec1/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
index fb3a959..a50229e 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsEqualsIndexOfTest.java
@@ -23,7 +23,7 @@ import static org.junit.Assert.assertTrue;
 
 import java.util.Locale;
 
-import org.apache.commons.lang3.test.SwitchDefaults;
+import org.apache.commons.lang3.test.SystemDefaultsSwitch;
 import org.apache.commons.lang3.test.SystemDefaults;
 import org.hamcrest.core.IsNot;
 import org.junit.Rule;
@@ -37,7 +37,7 @@ import org.junit.Test;
 public class StringUtilsEqualsIndexOfTest  {
 
     @Rule
-    public SwitchDefaults defaults = new SwitchDefaults();
+    public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
 
     private static final String BAR = "bar";
     /**

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bcb33ec1/src/test/java/org/apache/commons/lang3/test/SwitchDefaults.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/test/SwitchDefaults.java b/src/test/java/org/apache/commons/lang3/test/SwitchDefaults.java
deleted file mode 100644
index cacf37d..0000000
--- a/src/test/java/org/apache/commons/lang3/test/SwitchDefaults.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- * 
- *      http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.lang3.test;
-
-import java.util.Locale;
-import java.util.TimeZone;
-
-import org.apache.commons.lang3.LocaleUtils;
-import org.junit.rules.TestRule;
-import org.junit.runner.Description;
-import org.junit.runners.model.Statement;
-
-/**
- * Test Rule used with {@link SystemDefaults} annotation that sets and restores the system default Locale and TimeZone.
- * 
- * <p>
- * Set up tests to use alternate system default Locale and/or TimeZone by creating an instance of this rule
- * and annotating the test method with {@link SystemDefaults} 
- * </p>
- * 
- * <pre>
- * public class SystemDefaultsDependentTest {
- *
- *     {@literal@}Rule
- *     public SwitchDefaults locale = new SwitchDefaults();
- *
- *     {@literal@}Test
- *     public void testThatWillExecuteWithTheDefaultLocaleAndTimeZone() {
- *         // nothing to do, just implement the test
- *     }
- *
- *     {@literal@}Test
- *     {@literal@}SystemDefaults(local="zh_CN")
- *     public void testWithSimplifiedChinaDefaultLocale() {
- *         // Locale.getDefault() will return Locale.CHINA until the end of this test method
- *     }
- *      
- *     {@literal@}Test
- *     {@literal@}SystemDefaults(timezone="America/New_York")
- *     public void testWithNorthAmericaEasternTimeZone() {
- *         // TimeZone.getDefault() will equal TimeZone.getTimeZone("America/New_York") until the end of this method
- *     }
- * }
- * </pre>
- */
-public class SwitchDefaults implements TestRule {
-    
-    @Override
-    public Statement apply(Statement stmt, Description description) {
-        SystemDefaults defaults = description.getAnnotation(SystemDefaults.class);
-        if (defaults == null) {
-            return stmt;
-        }
-        return applyTimeZone(defaults, applyLocale(defaults, stmt));
-    }
-
-    private Statement applyTimeZone(SystemDefaults defaults, final Statement stmt) {
-        if (defaults.timezone().isEmpty()) {
-            return stmt;
-        }
-
-        final TimeZone newTimeZone = TimeZone.getTimeZone(defaults.timezone());
-
-        return new Statement() {
-            @Override
-            public void evaluate() throws Throwable {
-                TimeZone save = TimeZone.getDefault();
-                try {
-                    TimeZone.setDefault(newTimeZone);
-                    stmt.evaluate();
-                } finally {
-                    TimeZone.setDefault(save);
-                }
-            }
-        };
-    }
-
-    private Statement applyLocale(SystemDefaults defaults, final Statement stmt) {
-        if (defaults.locale().isEmpty()) {
-            return stmt;
-        }
-
-        final Locale newLocale = LocaleUtils.toLocale(defaults.locale());
-
-        return new Statement() {
-            @Override
-            public void evaluate() throws Throwable {
-                Locale save = Locale.getDefault();
-                try {
-                    Locale.setDefault(newLocale);
-                    stmt.evaluate();
-                } finally {
-                    Locale.setDefault(save);
-                }
-            }
-        };
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bcb33ec1/src/test/java/org/apache/commons/lang3/test/SystemDefaultsSwitch.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/test/SystemDefaultsSwitch.java b/src/test/java/org/apache/commons/lang3/test/SystemDefaultsSwitch.java
new file mode 100644
index 0000000..5e5cd6c
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/test/SystemDefaultsSwitch.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.lang3.test;
+
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.apache.commons.lang3.LocaleUtils;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * Test Rule used with {@link SystemDefaults} annotation that sets and restores the system default Locale and TimeZone.
+ * 
+ * <p>
+ * Set up tests to use alternate system default Locale and/or TimeZone by creating an instance of this rule
+ * and annotating the test method with {@link SystemDefaults} 
+ * </p>
+ * 
+ * <pre>
+ * public class SystemDefaultsDependentTest {
+ *
+ *     {@literal@}Rule
+ *     public SystemDefaultsSwitch locale = new SystemDefaultsSwitch();
+ *
+ *     {@literal@}Test
+ *     public void testThatWillExecuteWithTheDefaultLocaleAndTimeZone() {
+ *         // nothing to do, just implement the test
+ *     }
+ *
+ *     {@literal@}Test
+ *     {@literal@}SystemDefaults(local="zh_CN")
+ *     public void testWithSimplifiedChinaDefaultLocale() {
+ *         // Locale.getDefault() will return Locale.CHINA until the end of this test method
+ *     }
+ *      
+ *     {@literal@}Test
+ *     {@literal@}SystemDefaults(timezone="America/New_York")
+ *     public void testWithNorthAmericaEasternTimeZone() {
+ *         // TimeZone.getDefault() will equal TimeZone.getTimeZone("America/New_York") until the end of this method
+ *     }
+ * }
+ * </pre>
+ */
+public class SystemDefaultsSwitch implements TestRule {
+    
+    @Override
+    public Statement apply(Statement stmt, Description description) {
+        SystemDefaults defaults = description.getAnnotation(SystemDefaults.class);
+        if (defaults == null) {
+            return stmt;
+        }
+        return applyTimeZone(defaults, applyLocale(defaults, stmt));
+    }
+
+    private Statement applyTimeZone(SystemDefaults defaults, final Statement stmt) {
+        if (defaults.timezone().isEmpty()) {
+            return stmt;
+        }
+
+        final TimeZone newTimeZone = TimeZone.getTimeZone(defaults.timezone());
+
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                TimeZone save = TimeZone.getDefault();
+                try {
+                    TimeZone.setDefault(newTimeZone);
+                    stmt.evaluate();
+                } finally {
+                    TimeZone.setDefault(save);
+                }
+            }
+        };
+    }
+
+    private Statement applyLocale(SystemDefaults defaults, final Statement stmt) {
+        if (defaults.locale().isEmpty()) {
+            return stmt;
+        }
+
+        final Locale newLocale = LocaleUtils.toLocale(defaults.locale());
+
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                Locale save = Locale.getDefault();
+                try {
+                    Locale.setDefault(newLocale);
+                    stmt.evaluate();
+                } finally {
+                    Locale.setDefault(save);
+                }
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bcb33ec1/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
index af0cf8d..66c3d1e 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateFormatUtilsTest.java
@@ -29,7 +29,7 @@ import java.util.Date;
 import java.util.Locale;
 import java.util.TimeZone;
 
-import org.apache.commons.lang3.test.SwitchDefaults;
+import org.apache.commons.lang3.test.SystemDefaultsSwitch;
 import org.apache.commons.lang3.test.SystemDefaults;
 import org.junit.Rule;
 import org.junit.Test;
@@ -41,7 +41,7 @@ import org.junit.Test;
 public class DateFormatUtilsTest {
 
     @Rule
-    public SwitchDefaults defaults = new SwitchDefaults();
+    public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
     
     //-----------------------------------------------------------------------
     @Test

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bcb33ec1/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
index 44dbac5..4617ea9 100644
--- a/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/DateUtilsTest.java
@@ -38,7 +38,7 @@ import java.util.TimeZone;
 
 import junit.framework.AssertionFailedError;
 
-import org.apache.commons.lang3.test.SwitchDefaults;
+import org.apache.commons.lang3.test.SystemDefaultsSwitch;
 import org.apache.commons.lang3.test.SystemDefaults;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -61,7 +61,7 @@ public class DateUtilsTest {
     }
 
     @Rule
-    public SwitchDefaults defaults = new SwitchDefaults();
+    public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
     
     private DateFormat dateParser = null;
     private DateFormat dateTimeParser = null;

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bcb33ec1/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
index ee6d505..ba036c4 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDateFormatTest.java
@@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
-import org.apache.commons.lang3.test.SwitchDefaults;
+import org.apache.commons.lang3.test.SystemDefaultsSwitch;
 import org.apache.commons.lang3.test.SystemDefaults;
 import org.junit.Rule;
 import org.junit.Test;
@@ -49,7 +49,7 @@ import org.junit.Test;
 public class FastDateFormatTest {
 
     @Rule
-    public SwitchDefaults defaults = new SwitchDefaults();
+    public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
 
     /*
      * Only the cache methods need to be tested here.  

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/bcb33ec1/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java
index e0e44dc..7674b56 100644
--- a/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java
+++ b/src/test/java/org/apache/commons/lang3/time/FastDatePrinterTest.java
@@ -30,10 +30,8 @@ import java.util.Locale;
 import java.util.TimeZone;
 
 import org.apache.commons.lang3.SerializationUtils;
-import org.apache.commons.lang3.test.SwitchDefaults;
+import org.apache.commons.lang3.test.SystemDefaultsSwitch;
 import org.apache.commons.lang3.test.SystemDefaults;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
 import org.junit.Rule;
 import org.junit.Test;
 
@@ -79,7 +77,7 @@ public class FastDatePrinterTest {
     }
 
     @Rule
-    public SwitchDefaults defaults = new SwitchDefaults();
+    public SystemDefaultsSwitch defaults = new SystemDefaultsSwitch();
 
     @SystemDefaults(timezone="America/New_York", locale="en_US")
     @Test