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:43 UTC
[6/8] [lang] Write basic unit test for SystemDefaultsSwitch
Write basic unit test for SystemDefaultsSwitch
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/d68f7f5f
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/d68f7f5f
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/d68f7f5f
Branch: refs/heads/master
Commit: d68f7f5f44924ddee14428e16b7458e2878baef2
Parents: bcb33ec
Author: Benedikt Ritter <br...@apache.org>
Authored: Thu May 7 21:15:37 2015 +0200
Committer: Benedikt Ritter <br...@apache.org>
Committed: Thu May 7 21:15:37 2015 +0200
----------------------------------------------------------------------
.../lang3/test/SystemDefaultsSwitchTest.java | 88 ++++++++++++++++++++
1 file changed, 88 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/d68f7f5f/src/test/java/org/apache/commons/lang3/test/SystemDefaultsSwitchTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/test/SystemDefaultsSwitchTest.java b/src/test/java/org/apache/commons/lang3/test/SystemDefaultsSwitchTest.java
new file mode 100644
index 0000000..2d3c2f5
--- /dev/null
+++ b/src/test/java/org/apache/commons/lang3/test/SystemDefaultsSwitchTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+
+import java.util.Locale;
+import java.util.TimeZone;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class SystemDefaultsSwitchTest {
+
+ private static Locale TEST_DEFAULT_LOCALE;
+ private static Locale DEFAULT_LOCALE_BEFORE_TEST;
+
+ private static TimeZone DEFAULT_TIMEZONE_BEFORE_TEST;
+ private static TimeZone TEST_DEFAULT_TIMEZONE;
+
+ @BeforeClass
+ public static void classSetUp() {
+ DEFAULT_LOCALE_BEFORE_TEST = Locale.getDefault();
+ if (!DEFAULT_LOCALE_BEFORE_TEST.equals(Locale.CANADA)) {
+ Locale.setDefault(Locale.CANADA);
+ } else {
+ // you seem to be from Canada...
+ Locale.setDefault(Locale.CHINESE);
+ }
+ TEST_DEFAULT_LOCALE = Locale.getDefault();
+
+ DEFAULT_TIMEZONE_BEFORE_TEST = TimeZone.getDefault();
+ TimeZone utc = TimeZone.getTimeZone("UTC");
+ if (!DEFAULT_TIMEZONE_BEFORE_TEST.equals(utc)) {
+ TimeZone.setDefault(utc);
+ } else {
+ TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+ }
+ TEST_DEFAULT_TIMEZONE = TimeZone.getDefault();
+ }
+
+ @Rule
+ public SystemDefaultsSwitch defaultsSwitch = new SystemDefaultsSwitch();
+
+ @Test
+ public void testDefaultLocaleNoAnnotation() throws Exception {
+ assertEquals(TEST_DEFAULT_LOCALE, Locale.getDefault());
+ }
+
+ @Test
+ @SystemDefaults(locale = "en_EN")
+ public void testUseDifferentLocale() throws Exception {
+ assertEquals(new Locale("en", "EN"), Locale.getDefault());
+ }
+
+ @Test
+ public void testDefaultTimeZoneNoAnnotation() throws Exception {
+ assertEquals(TEST_DEFAULT_TIMEZONE, TimeZone.getDefault());
+ }
+
+ @Test
+ @SystemDefaults(timezone = "CET")
+ public void testUseDifferentTimeZone() throws Exception {
+ assertEquals(TimeZone.getTimeZone("CET"), TimeZone.getDefault());
+ }
+
+ @AfterClass
+ public static void classTearDown() {
+ Locale.setDefault(DEFAULT_LOCALE_BEFORE_TEST);
+ TimeZone.setDefault(DEFAULT_TIMEZONE_BEFORE_TEST);
+ }
+}