incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r1088956 - /sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider_KeyTest.java
Date Tue, 05 Apr 2011 10:20:43 GMT
Author: fmeschbe
Date: Tue Apr  5 10:20:42 2011
New Revision: 1088956

URL: http://svn.apache.org/viewvc?rev=1088956&view=rev
Log:
SLING-2048 Testcases for the Key

Added:
    sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider_KeyTest.java
  (with props)

Added: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider_KeyTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider_KeyTest.java?rev=1088956&view=auto
==============================================================================
--- sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider_KeyTest.java
(added)
+++ sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider_KeyTest.java
Tue Apr  5 10:20:42 2011
@@ -0,0 +1,146 @@
+/*
+ * 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.sling.i18n.impl;
+
+import java.lang.reflect.Constructor;
+import java.util.Locale;
+
+import junit.framework.TestCase;
+
+public class JcrResourceBundleProvider_KeyTest extends TestCase {
+
+    private Constructor<?> ctor;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        try {
+            Class<?> clazz = getClass().getClassLoader().loadClass(
+                "org.apache.sling.i18n.impl.JcrResourceBundleProvider$Key");
+            this.ctor = clazz.getDeclaredConstructor(String.class, Locale.class);
+        } catch (Throwable t) {
+            fail("Cannot get JcrResourceBundleProvider.Key constructor: " + t);
+        }
+    }
+
+    public void test_key_null_null() {
+        final Object key1 = createKey(null, null);
+        assertNotNull(key1);
+        assertEquals(0, key1.hashCode());
+
+        final Object key2 = createKey(null, null);
+        assertNotNull(key2);
+        assertEquals(0, key2.hashCode());
+
+        assertEquals(key1, key1);
+        assertEquals(key2, key2);
+        assertEquals(key1, key2);
+
+        assertFalse(key1.equals(null));
+        assertFalse(key2.equals(null));
+
+        assertFalse(key1.equals("string"));
+        assertFalse(key2.equals("string"));
+    }
+
+    public void test_key_null_Locale() {
+        final Object key1 = createKey(null, new Locale("de"));
+        assertNotNull(key1);
+
+        final Object key2 = createKey(null, new Locale("de"));
+        assertNotNull(key2);
+
+        assertEquals(key1.hashCode(), key2.hashCode());
+
+        assertEquals(key1, key1);
+        assertEquals(key2, key2);
+        assertEquals(key1, key2);
+
+        assertFalse(key1.equals(null));
+        assertFalse(key2.equals(null));
+
+        assertFalse(key1.equals("string"));
+        assertFalse(key2.equals("string"));
+    }
+
+
+    public void test_key_String_null() {
+        final Object key1 = createKey("base", null);
+        assertNotNull(key1);
+
+        final Object key2 = createKey("base", null);
+        assertNotNull(key2);
+
+        assertEquals(key1.hashCode(), key2.hashCode());
+
+        assertEquals(key1, key1);
+        assertEquals(key2, key2);
+        assertEquals(key1, key2);
+
+        assertFalse(key1.equals(null));
+        assertFalse(key2.equals(null));
+
+        assertFalse(key1.equals("string"));
+        assertFalse(key2.equals("string"));
+
+        assertEquals(key1, createKey("base", null));
+        assertFalse(key1.equals(createKey("other", null)));
+        assertFalse(key1.equals(createKey("base", new Locale("de"))));
+        assertFalse(key1.equals(createKey(null, new Locale("de"))));
+        assertFalse(key1.equals(createKey(null, null)));
+    }
+
+
+    public void test_key_String_Locale() {
+        final Object key1 = createKey("base", new Locale("de"));
+        assertNotNull(key1);
+
+        final Object key2 = createKey("base", new Locale("de"));
+        assertNotNull(key2);
+
+        assertEquals(key1.hashCode(), key2.hashCode());
+
+        assertEquals(key1, key1);
+        assertEquals(key2, key2);
+        assertEquals(key1, key2);
+
+        assertFalse(key1.equals(null));
+        assertFalse(key2.equals(null));
+
+        assertFalse(key1.equals("string"));
+        assertFalse(key2.equals("string"));
+
+        assertEquals(key1, createKey("base", new Locale("de")));
+        assertFalse(key1.equals(createKey("other", null)));
+        assertFalse(key1.equals(createKey("other", new Locale("de"))));
+        assertFalse(key1.equals(createKey("base", new Locale("en"))));
+        assertFalse(key1.equals(createKey(null, new Locale("de"))));
+        assertFalse(key1.equals(createKey(null, null)));
+    }
+
+    private Object createKey(final String baseName, final Locale locale) {
+        try {
+            return ctor.newInstance(baseName, locale);
+        } catch (Throwable t) {
+            fail("Cannot create Key instance: " + t);
+            return null; // keep compiler quiet
+        }
+    }
+}

Propchange: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider_KeyTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/contrib/extensions/i18n/src/test/java/org/apache/sling/i18n/impl/JcrResourceBundleProvider_KeyTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url



Mime
View raw message