From e32b21f14d52bac429a9c54fe031f9e92c911d64 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Thu, 17 Jun 2010 18:34:43 -0700 Subject: [PATCH] Implementing ZoneInfo.hasSameRules(). Moving TimeZoneTest to OldTimeZoneTest and removing test methods that are duplicated between libcore and Harmony. Also adding Objects.equals() to make implementing this easy, and removing redundant time zone tests. I did a few searches to find candidate code that could take advantage of this new utility method and adopted it there. Change-Id: I133298f1b36d755bd35c1ad0dc0ab366fd164270 --- expectations/brokentests.txt | 5 + luni/src/main/java/java/io/File.java | 10 +- luni/src/main/java/java/io/FilePermission.java | 7 +- luni/src/main/java/java/net/HttpCookie.java | 5 +- luni/src/main/java/java/net/URLStreamHandler.java | 49 +-- luni/src/main/java/java/security/Identity.java | 4 +- luni/src/main/java/java/text/MessageFormat.java | 3 +- luni/src/main/java/java/util/HashMap.java | 17 +- luni/src/main/java/java/util/TimeZone.java | 2 +- luni/src/main/java/java/util/TreeMap.java | 5 +- luni/src/main/java/java/util/logging/Level.java | 6 +- luni/src/main/java/libcore/base/Objects.java | 28 ++ .../harmony/luni/internal/util/ZoneInfo.java | 79 ++-- .../harmony/security/asn1/DerOutputStream.java | 5 +- .../xnet/provider/jsse/OpenSSLSessionImpl.java | 10 +- .../harmony/xnet/provider/jsse/SSLSessionImpl.java | 4 +- luni/src/test/java/java/util/OldTimeZoneTest.java | 235 ++++++++++++ .../tests/java/security/KeyStore2Test.java | 2 +- .../tests/java/security/Security2Test.java | 5 +- .../test/java/tests/api/java/util/AllTests.java | 1 - .../java/tests/api/java/util/TimeZoneTest.java | 414 --------------------- .../serialization/SerializationTest.java | 3 +- 22 files changed, 355 insertions(+), 544 deletions(-) create mode 100644 luni/src/main/java/libcore/base/Objects.java create mode 100644 luni/src/test/java/java/util/OldTimeZoneTest.java delete mode 100644 luni/src/test/java/tests/api/java/util/TimeZoneTest.java diff --git a/expectations/brokentests.txt b/expectations/brokentests.txt index cb609a75..c6dcfccb 100644 --- a/expectations/brokentests.txt +++ b/expectations/brokentests.txt @@ -654,6 +654,11 @@ test tests.api.java.nio.charset.UTFCharsetEncoderTest#testSpecificDefaultValue result EXEC_FAILED pattern .*junit.framework.AssertionFailedError: expected:<1.1> but was:<2.0>.* +# We don't permit runtime switching of the default charset (and neither does the RI) +test org.apache.harmony.nio_char.tests.java.nio.charset.CharsetTest#test_defaultCharset +result EXEC_FAILED +pattern .*expected: but was:.* + # this test needs external interaction test com.sun.tools.attach.Application result UNSUPPORTED diff --git a/luni/src/main/java/java/io/File.java b/luni/src/main/java/java/io/File.java index 57f6609c..168d2ac3 100644 --- a/luni/src/main/java/java/io/File.java +++ b/luni/src/main/java/java/io/File.java @@ -36,10 +36,8 @@ import java.security.AccessController; import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; - import org.apache.harmony.luni.util.DeleteOnExit; import org.apache.harmony.luni.util.PriviAction; -import org.apache.harmony.luni.util.Util; /** * An "abstract" representation of a file system entity identified by a @@ -260,19 +258,17 @@ public class File implements Serializable, Comparable { return haveSlash ? (prefix + suffix) : (prefix + separatorChar + suffix); } - @SuppressWarnings("nls") private void checkURI(URI uri) { if (!uri.isAbsolute()) { throw new IllegalArgumentException("URI is not absolute: " + uri); } else if (!uri.getRawSchemeSpecificPart().startsWith("/")) { throw new IllegalArgumentException("URI is not hierarchical: " + uri); } - String temp = uri.getScheme(); - if (temp == null || !temp.equals("file")) { + if (!"file".equals(uri.getScheme())) { throw new IllegalArgumentException("Expected file scheme in URI: " + uri); } - temp = uri.getRawPath(); - if (temp == null || temp.isEmpty()) { + String rawPath = uri.getRawPath(); + if (rawPath == null || rawPath.isEmpty()) { throw new IllegalArgumentException("Expected non-empty path in URI: " + uri); } if (uri.getRawAuthority() != null) { diff --git a/luni/src/main/java/java/io/FilePermission.java b/luni/src/main/java/java/io/FilePermission.java index 6d6e0dca..8216086c 100644 --- a/luni/src/main/java/java/io/FilePermission.java +++ b/luni/src/main/java/java/io/FilePermission.java @@ -21,6 +21,7 @@ import java.security.AccessController; import java.security.Permission; import java.security.PermissionCollection; import java.security.PrivilegedAction; +import libcore.base.Objects; /** * A permission for accessing a file or directory. The FilePermission is made up @@ -210,10 +211,8 @@ public final class FilePermission extends Permission implements Serializable { public boolean equals(Object obj) { if (obj instanceof FilePermission) { FilePermission fp = (FilePermission) obj; - if (fp.actions != actions) { - if (fp.actions == null || !fp.actions.equals(actions)) { - return false; - } + if (!Objects.equal(fp.actions, actions)) { + return false; } /* Matching actions and both are <> ? */ diff --git a/luni/src/main/java/java/net/HttpCookie.java b/luni/src/main/java/java/net/HttpCookie.java index dfd7fe10..fcdaf756 100644 --- a/luni/src/main/java/java/net/HttpCookie.java +++ b/luni/src/main/java/java/net/HttpCookie.java @@ -26,6 +26,7 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Set; +import libcore.base.Objects; /** * An opaque key-value value pair held by an HTTP client to permit a stateful @@ -725,7 +726,7 @@ public final class HttpCookie implements Cloneable { HttpCookie that = (HttpCookie) object; return name.equalsIgnoreCase(that.getName()) && (domain != null ? domain.equalsIgnoreCase(that.domain) : that.domain == null) - && (path != null ? path.equals(that.path) : that.path == null); + && Objects.equal(path, that.path); } return false; } @@ -773,4 +774,4 @@ public final class HttpCookie implements Cloneable { builder.append("\""); } } -} \ No newline at end of file +} diff --git a/luni/src/main/java/java/net/URLStreamHandler.java b/luni/src/main/java/java/net/URLStreamHandler.java index 3fbed562..d95b2a52 100644 --- a/luni/src/main/java/java/net/URLStreamHandler.java +++ b/luni/src/main/java/java/net/URLStreamHandler.java @@ -18,6 +18,7 @@ package java.net; import java.io.IOException; +import libcore.base.Objects; import org.apache.harmony.luni.util.URLUtil; /** @@ -339,13 +340,8 @@ public abstract class URLStreamHandler { if (!sameFile(url1, url2)) { return false; } - String s1 = url1.getRef(), s2 = url2.getRef(); - if (s1 != s2 && (s1 == null || !s1.equals(s2))) { - return false; - } - s1 = url1.getQuery(); - s2 = url2.getQuery(); - return s1 == s2 || (s1 != null && s1.equals(s2)); + return Objects.equal(url1.getRef(), url2.getRef()) + && Objects.equal(url1.getQuery(), url2.getQuery()); } /** @@ -400,16 +396,8 @@ public abstract class URLStreamHandler { */ protected boolean hostsEqual(URL url1, URL url2) { String host1 = getHost(url1), host2 = getHost(url2); - if (host1 != null && host1.equalsIgnoreCase(host2)) { - return true; - } - // Compare host address if the host name is not equal. - InetAddress address1 = getHostAddress(url1); - InetAddress address2 = getHostAddress(url2); - if (address1 != null && address1.equals(address2)) { - return true; - } - return false; + return (host1 != null && host1.equalsIgnoreCase(host2)) + || Objects.equal(getHostAddress(url1), getHostAddress(url2)); } /** @@ -424,29 +412,10 @@ public abstract class URLStreamHandler { * otherwise. */ protected boolean sameFile(URL url1, URL url2) { - String s1 = url1.getProtocol(); - String s2 = url2.getProtocol(); - if (s1 != s2 && (s1 == null || !s1.equals(s2))) { - return false; - } - - s1 = url1.getFile(); - s2 = url2.getFile(); - if (s1 != s2 && (s1 == null || !s1.equals(s2))) { - return false; - } - if (!hostsEqual(url1, url2)) { - return false; - } - int p1 = url1.getPort(); - if (p1 == -1) { - p1 = getDefaultPort(); - } - int p2 = url2.getPort(); - if (p2 == -1) { - p2 = getDefaultPort(); - } - return p1 == p2; + return Objects.equal(url1.getProtocol(), url2.getProtocol()) + && Objects.equal(url1.getFile(), url2.getFile()) + && hostsEqual(url1, url2) + && url1.getEffectivePort() == url2.getEffectivePort(); } /* diff --git a/luni/src/main/java/java/security/Identity.java b/luni/src/main/java/java/security/Identity.java index b8696a68..b3583905 100644 --- a/luni/src/main/java/java/security/Identity.java +++ b/luni/src/main/java/java/security/Identity.java @@ -20,6 +20,7 @@ package java.security; import java.io.Serializable; import java.util.Vector; import java.util.Arrays; +import libcore.base.Objects; /** * {@code Identity} represents an identity like a person or a company. @@ -356,8 +357,7 @@ public abstract class Identity implements Principal, Serializable { return false; } Identity i = (Identity) obj; - if ((name == i.name || (name != null && name.equals(i.name))) - && (scope == i.scope || (scope != null && scope.equals(i.scope)))) { + if (Objects.equal(name, i.name) && (Objects.equal(scope, i.scope))) { return true; } return identityEquals(i); diff --git a/luni/src/main/java/java/text/MessageFormat.java b/luni/src/main/java/java/text/MessageFormat.java index e45c3863..824ddb87 100644 --- a/luni/src/main/java/java/text/MessageFormat.java +++ b/luni/src/main/java/java/text/MessageFormat.java @@ -27,6 +27,7 @@ import java.util.Date; import java.util.Iterator; import java.util.Locale; import java.util.Vector; +import libcore.base.Objects; /** * Produces concatenated messages in language-neutral way. New code @@ -1333,7 +1334,7 @@ public class MessageFormat extends Format { @Override protected Object readResolve() throws InvalidObjectException { String name = this.getName(); - if (name != null && name.equals(ARGUMENT.getName())) { + if (Objects.equal(name, ARGUMENT.getName())) { return ARGUMENT; } throw new InvalidObjectException("Not a valid MessageFormat.Field, subclass should override readResolve()"); diff --git a/luni/src/main/java/java/util/HashMap.java b/luni/src/main/java/java/util/HashMap.java index ecad473d..1e5bd0ef 100644 --- a/luni/src/main/java/java/util/HashMap.java +++ b/luni/src/main/java/java/util/HashMap.java @@ -27,6 +27,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.ObjectStreamField; import java.io.Serializable; +import libcore.base.Objects; /** * HashMap is an implementation of {@link Map}. All optional operations are supported. @@ -755,8 +756,8 @@ public class HashMap extends AbstractMap implements Cloneable, Seria return false; } Entry e = (Entry) o; - return HashMap.equals(e.getKey(), key) - && HashMap.equals(e.getValue(), value); + return Objects.equal(e.getKey(), key) + && Objects.equal(e.getValue(), value); } @Override public final int hashCode() { @@ -838,7 +839,7 @@ public class HashMap extends AbstractMap implements Cloneable, Seria private boolean containsMapping(Object key, Object value) { if (key == null) { HashMapEntry e = entryForNullKey; - return e != null && equals(value, e.value); + return e != null && Objects.equal(value, e.value); } int hash = secondaryHash(key.hashCode()); @@ -846,7 +847,7 @@ public class HashMap extends AbstractMap implements Cloneable, Seria int index = hash & (tab.length - 1); for (HashMapEntry e = tab[index]; e != null; e = e.next) { if (e.hash == hash && key.equals(e.key)) { - return equals(value, e.value); + return Objects.equal(value, e.value); } } return false; // No entry for key @@ -859,7 +860,7 @@ public class HashMap extends AbstractMap implements Cloneable, Seria private boolean removeMapping(Object key, Object value) { if (key == null) { HashMapEntry e = entryForNullKey; - if (e == null || !equals(value, e.value)) { + if (e == null || !Objects.equal(value, e.value)) { return false; } entryForNullKey = null; @@ -875,7 +876,7 @@ public class HashMap extends AbstractMap implements Cloneable, Seria for (HashMapEntry e = tab[index], prev = null; e != null; prev = e, e = e.next) { if (e.hash == hash && key.equals(e.key)) { - if (!equals(value, e.value)) { + if (!Objects.equal(value, e.value)) { return false; // Map has wrong value for key } if (prev == null) { @@ -892,10 +893,6 @@ public class HashMap extends AbstractMap implements Cloneable, Seria return false; // No entry for key } - private static boolean equals(Object o1, Object o2) { - return o1 == o2 || (o1 != null && o1.equals(o2)); - } - // Subclass (LinkedHashMap) overrides these for correct iteration order Iterator newKeyIterator() { return new KeyIterator(); } Iterator newValueIterator() { return new ValueIterator(); } diff --git a/luni/src/main/java/java/util/TimeZone.java b/luni/src/main/java/java/util/TimeZone.java index 0b6252d7..540681ed 100644 --- a/luni/src/main/java/java/util/TimeZone.java +++ b/luni/src/main/java/java/util/TimeZone.java @@ -277,7 +277,7 @@ public abstract class TimeZone implements Serializable, Cloneable { * Returns a time zone whose ID is {@code id}. Time zone IDs are typically * named by geographic identifiers like {@code America/Los_Angeles} or GMT * offsets like {@code GMT-8:00}. Three letter IDs like {@code PST} are - * supported but should not be used because they is often ambiguous. + * supported but should not be used because they are often ambiguous. * * @return a time zone with the specified ID, or {@code GMT} if the ID * is not recognized and cannot be parsed. diff --git a/luni/src/main/java/java/util/TreeMap.java b/luni/src/main/java/java/util/TreeMap.java index 5c0f8f42..a11ab1a9 100644 --- a/luni/src/main/java/java/util/TreeMap.java +++ b/luni/src/main/java/java/util/TreeMap.java @@ -30,6 +30,7 @@ import static java.util.TreeMap.Relation.EQUAL; import static java.util.TreeMap.Relation.FLOOR; import static java.util.TreeMap.Relation.HIGHER; import static java.util.TreeMap.Relation.LOWER; +import libcore.base.Objects; /** * A map whose entries are sorted by their keys. All optional operations such as @@ -367,9 +368,7 @@ public class TreeMap extends AbstractMap */ Node findByEntry(Entry entry) { Node mine = findByObject(entry.getKey()); - boolean valuesEqual = mine != null && (mine.value != null - ? mine.value.equals(entry.getValue()) - : entry.getValue() == null); + boolean valuesEqual = mine != null && Objects.equal(mine.value, entry.getValue()); return valuesEqual ? mine : null; } diff --git a/luni/src/main/java/java/util/logging/Level.java b/luni/src/main/java/java/util/logging/Level.java index b84bbbd5..ee65166d 100644 --- a/luni/src/main/java/java/util/logging/Level.java +++ b/luni/src/main/java/java/util/logging/Level.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import java.util.MissingResourceException; import java.util.ResourceBundle; +import libcore.base.Objects; /** * {@code Level} objects are used to indicate the level of logging. There are a @@ -262,10 +263,7 @@ public class Level implements Serializable { if (!name.equals(level.name)) { continue; } - if (resourceBundleName == level.resourceBundleName) { - return level; - } else if (resourceBundleName != null - && resourceBundleName.equals(level.resourceBundleName)) { + if (Objects.equal(resourceBundleName, level.resourceBundleName)) { return level; } } diff --git a/luni/src/main/java/libcore/base/Objects.java b/luni/src/main/java/libcore/base/Objects.java new file mode 100644 index 00000000..4c420b88 --- /dev/null +++ b/luni/src/main/java/libcore/base/Objects.java @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed 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 libcore.base; + +public final class Objects { + private Objects() {} + + /** + * Returns true if two possibly-null objects are equal. + */ + public static boolean equal(Object a, Object b) { + return a == b || (a != null && a.equals(b)); + } +} diff --git a/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java b/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java index db1d136c..0e95abaf 100644 --- a/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java +++ b/luni/src/main/java/org/apache/harmony/luni/internal/util/ZoneInfo.java @@ -20,11 +20,9 @@ import java.io.IOException; import java.util.Arrays; import java.util.Date; import java.util.TimeZone; +import libcore.base.Objects; -/** - * {@hide} - */ -public class ZoneInfo extends TimeZone { +public final class ZoneInfo extends TimeZone { private static final long MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000; private static final long MILLISECONDS_PER_400_YEARS = @@ -41,8 +39,7 @@ public class ZoneInfo extends TimeZone { }; public static TimeZone getTimeZone(String name) { - if (name == null) - { + if (name == null) { return null; } @@ -54,17 +51,28 @@ public class ZoneInfo extends TimeZone { } private static String nullName(byte[] data, int where, int off) { - if (off < 0) + if (off < 0) { return null; + } int end = where + off; - while (end < data.length && data[end] != '\0') + while (end < data.length && data[end] != '\0') { end++; + } return new String(data, where + off, end - (where + off)); } - /*package*/ ZoneInfo(String name, int[] transitions, byte[] type, + private int mRawOffset; + private int[] mTransitions; + private int[] mGmtOffs; + private byte[] mTypes; + private byte[] mIsDsts; + private boolean mUseDst; + private String mDaylightName; + private String mStandardName; + + ZoneInfo(String name, int[] transitions, byte[] type, int[] gmtoff, byte[] isdst, byte[] abbrev, byte[] data, int abbrevoff) { mTransitions = transitions; @@ -136,10 +144,7 @@ public class ZoneInfo extends TimeZone { } @Override - public int getOffset(@SuppressWarnings("unused") int era, - int year, int month, int day, - @SuppressWarnings("unused") int dayOfWeek, - int millis) { + public int getOffset(int era, int year, int month, int day, int dayOfWeek, int millis) { // XXX This assumes Gregorian always; Calendar switches from // Julian to Gregorian in 1582. What calendar system are the // arguments supposed to come from? @@ -211,30 +216,18 @@ public class ZoneInfo extends TimeZone { return mUseDst; } - private int mRawOffset; - private int[] mTransitions; - private int[] mGmtOffs; - private byte[] mTypes; - private byte[] mIsDsts; - private boolean mUseDst; - private String mDaylightName; - private String mStandardName; - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; + @Override public boolean hasSameRules(TimeZone timeZone) { + if (!(timeZone instanceof ZoneInfo)) { + return false; } - if (!(obj instanceof ZoneInfo)) { - return false; + ZoneInfo other = (ZoneInfo) timeZone; + if (mUseDst != other.mUseDst) { + return false; } - ZoneInfo other = (ZoneInfo) obj; - return mUseDst == other.mUseDst - && (mDaylightName == null ? other.mDaylightName == null : - mDaylightName.equals(other.mDaylightName)) - && (mStandardName == null ? other.mStandardName == null : - mStandardName.equals(other.mStandardName)) - && mRawOffset == other.mRawOffset + if (!mUseDst) { + return mRawOffset == other.mRawOffset; + } + return mRawOffset == other.mRawOffset // Arrays.equals returns true if both arrays are null && Arrays.equals(mGmtOffs, other.mGmtOffs) && Arrays.equals(mIsDsts, other.mIsDsts) @@ -242,17 +235,25 @@ public class ZoneInfo extends TimeZone { && Arrays.equals(mTransitions, other.mTransitions); } + @Override public boolean equals(Object obj) { + if (!(obj instanceof ZoneInfo)) { + return false; + } + ZoneInfo other = (ZoneInfo) obj; + return Objects.equal(mDaylightName, other.mDaylightName) + && Objects.equal(mStandardName, other.mStandardName) + && hasSameRules(other); + } + @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((mDaylightName == null) ? 0 : - mDaylightName.hashCode()); + result = prime * result + ((mDaylightName == null) ? 0 : mDaylightName.hashCode()); result = prime * result + Arrays.hashCode(mGmtOffs); result = prime * result + Arrays.hashCode(mIsDsts); result = prime * result + mRawOffset; - result = prime * result + ((mStandardName == null) ? 0 : - mStandardName.hashCode()); + result = prime * result + ((mStandardName == null) ? 0 : mStandardName.hashCode()); result = prime * result + Arrays.hashCode(mTransitions); result = prime * result + Arrays.hashCode(mTypes); result = prime * result + (mUseDst ? 1231 : 1237); diff --git a/luni/src/main/java/org/apache/harmony/security/asn1/DerOutputStream.java b/luni/src/main/java/org/apache/harmony/security/asn1/DerOutputStream.java index e0e8a7d1..b8b9d1c3 100644 --- a/luni/src/main/java/org/apache/harmony/security/asn1/DerOutputStream.java +++ b/luni/src/main/java/org/apache/harmony/security/asn1/DerOutputStream.java @@ -22,6 +22,8 @@ package org.apache.harmony.security.asn1; +import libcore.base.Objects; + /** * Encodes ASN.1 types with DER (X.690) @@ -200,8 +202,7 @@ public final class DerOutputStream extends BerOutputStream { } } - if (sequence.DEFAULT[i] != null - && sequence.DEFAULT[i].equals(values[i])) { + if (Objects.equal(sequence.DEFAULT[i], values[i])) { values[i] = null; continue; } diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java index 14ccea29..8e6e59d9 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/OpenSSLSessionImpl.java @@ -22,8 +22,6 @@ import java.security.AccessController; import java.security.Principal; import java.security.cert.Certificate; import java.security.cert.X509Certificate; -import java.util.Iterator; -import java.util.Map; import java.util.Vector; import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLPermission; @@ -32,6 +30,7 @@ import javax.net.ssl.SSLSessionBindingEvent; import javax.net.ssl.SSLSessionBindingListener; import javax.net.ssl.SSLSessionContext; import javax.security.cert.CertificateEncodingException; +import libcore.base.Objects; import org.apache.harmony.luni.util.TwoKeyHashMap; import org.apache.harmony.security.provider.cert.X509CertImpl; @@ -417,11 +416,10 @@ public class OpenSSLSessionImpl implements SSLSession { Vector v = new Vector(); AccessControlContext current = AccessController.getContext(); AccessControlContext cont; - for (Iterator it = values.entrySet().iterator(); it.hasNext();) { - TwoKeyHashMap.Entry entry = (TwoKeyHashMap.Entry) it.next(); + for (Object o : values.entrySet()) { + TwoKeyHashMap.Entry entry = (TwoKeyHashMap.Entry) o; cont = (AccessControlContext) entry.getKey2(); - if ((current == null && cont == null) - || (current != null && current.equals(cont))) { + if (Objects.equal(current, cont == null)) { v.add(entry.getKey1()); } } diff --git a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java index 5fec6dd8..a75064b6 100644 --- a/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java +++ b/luni/src/main/java/org/apache/harmony/xnet/provider/jsse/SSLSessionImpl.java @@ -34,6 +34,7 @@ import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSessionBindingEvent; import javax.net.ssl.SSLSessionBindingListener; import javax.net.ssl.SSLSessionContext; +import libcore.base.Objects; /** * @@ -298,8 +299,7 @@ public class SSLSessionImpl implements SSLSession, Cloneable { final Vector v = new Vector(); final AccessControlContext currAcc = AccessController.getContext(); for (ValueKey key : values.keySet()) { - if ((currAcc == null && key.acc == null) - || (currAcc != null && currAcc.equals(key.acc))) { + if (Objects.equal(currAcc, key.acc)) { v.add(key.name); } } diff --git a/luni/src/test/java/java/util/OldTimeZoneTest.java b/luni/src/test/java/java/util/OldTimeZoneTest.java new file mode 100644 index 00000000..126e787e --- /dev/null +++ b/luni/src/test/java/java/util/OldTimeZoneTest.java @@ -0,0 +1,235 @@ +/* + * 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 java.util; + +import dalvik.annotation.AndroidOnly; +import dalvik.annotation.TestLevel; +import dalvik.annotation.TestTargetClass; +import dalvik.annotation.TestTargetNew; +import junit.framework.TestCase; +import tests.support.Support_Locale; + +@TestTargetClass(TimeZone.class) +public class OldTimeZoneTest extends TestCase { + + class Mock_TimeZone extends TimeZone { + @Override + public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) { + return 0; + } + + @Override + public int getRawOffset() { + return 0; + } + + @Override + public boolean inDaylightTime(Date date) { + return false; + } + + @Override + public void setRawOffset(int offsetMillis) { + + } + + @Override + public boolean useDaylightTime() { + return false; + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "TimeZone", + args = {} + ) + public void test_constructor() { + assertNotNull(new Mock_TimeZone()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "clone", + args = {} + ) + public void test_clone() { + TimeZone tz1 = TimeZone.getDefault(); + TimeZone tz2 = (TimeZone)tz1.clone(); + + assertTrue(tz1.equals(tz2)); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAvailableIDs", + args = {} + ) + public void test_getAvailableIDs() { + String[] str = TimeZone.getAvailableIDs(); + assertNotNull(str); + assertTrue(str.length != 0); + for(int i = 0; i < str.length; i++) { + assertNotNull(TimeZone.getTimeZone(str[i])); + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getAvailableIDs", + args = {int.class} + ) + public void test_getAvailableIDsI() { + String[] str = TimeZone.getAvailableIDs(0); + assertNotNull(str); + assertTrue(str.length != 0); + for(int i = 0; i < str.length; i++) { + assertNotNull(TimeZone.getTimeZone(str[i])); + } + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getDisplayName", + args = {} + ) + public void test_getDisplayName() { + TimeZone tz = TimeZone.getTimeZone("GMT-6"); + assertEquals("GMT-06:00", tz.getDisplayName()); + tz = TimeZone.getTimeZone("America/Los_Angeles"); + assertEquals("Pacific Standard Time", tz.getDisplayName()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getDisplayName", + args = {java.util.Locale.class} + ) + public void test_getDisplayNameLjava_util_Locale() { + Locale[] requiredLocales = {Locale.US, Locale.FRANCE}; + if (!Support_Locale.areLocalesAvailable(requiredLocales)) { + // locale dependent test, bug 1943269 + return; + } + TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); + assertEquals("Pacific Standard Time", tz.getDisplayName(new Locale("US"))); + // BEGIN android-note: RI has "Heure", CLDR/ICU has "heure". + assertEquals("heure normale du Pacifique", tz.getDisplayName(Locale.FRANCE)); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getDisplayName", + args = {boolean.class, int.class} + ) + public void test_getDisplayNameZI() { + TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); + assertEquals("PST", tz.getDisplayName(false, 0)); + assertEquals("Pacific Daylight Time", tz.getDisplayName(true, 1)); + assertEquals("Pacific Standard Time", tz.getDisplayName(false, 1)); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getDisplayName", + args = {boolean.class, int.class, java.util.Locale.class} + ) + @AndroidOnly("fail on RI. See comment below") + public void test_getDisplayNameZILjava_util_Locale() { + Locale[] requiredLocales = {Locale.US, Locale.UK, Locale.FRANCE}; + if (!Support_Locale.areLocalesAvailable(requiredLocales)) { + // locale dependent test, bug 1943269 + return; + } + TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); + assertEquals("PST", tz.getDisplayName(false, 0, Locale.US)); + assertEquals("Pacific Daylight Time", tz.getDisplayName(true, 1, Locale.US)); + assertEquals("Pacific Standard Time", tz.getDisplayName(false, 1, Locale.UK)); + //RI fails on following line. RI always returns short time zone name as "PST" + assertEquals("UTC-08:00", tz.getDisplayName(false, 0, Locale.FRANCE)); + // BEGIN android-note: RI has "Heure", CLDR/ICU has "heure". + assertEquals("heure avanc\u00e9e du Pacifique", tz.getDisplayName(true, 1, Locale.FRANCE)); + assertEquals("heure normale du Pacifique", tz.getDisplayName(false, 1, Locale.FRANCE)); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "getID", + args = {} + ) + public void test_getID() { + TimeZone tz = TimeZone.getTimeZone("GMT-6"); + assertEquals("GMT-06:00", tz.getID()); + tz = TimeZone.getTimeZone("America/Denver"); + assertEquals("America/Denver", tz.getID()); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "hasSameRules", + args = {java.util.TimeZone.class} + ) + public void test_hasSameRulesLjava_util_TimeZone() { + TimeZone tz1 = TimeZone.getTimeZone("America/Denver"); + TimeZone tz2 = TimeZone.getTimeZone("America/Phoenix"); + assertEquals(tz1.getDisplayName(false, 0), tz2.getDisplayName(false, 0)); + // Arizona doesn't observe DST. See http://phoenix.about.com/cs/weather/qt/timezone.htm + assertFalse(tz1.hasSameRules(tz2)); + assertFalse(tz1.hasSameRules(null)); + tz1 = TimeZone.getTimeZone("America/Montreal"); + tz2 = TimeZone.getTimeZone("America/New_York"); + assertEquals(tz1.getDisplayName(), tz2.getDisplayName()); + assertFalse(tz1.getID().equals(tz2.getID())); + assertTrue(tz2.hasSameRules(tz1)); + assertTrue(tz1.hasSameRules(tz1)); + } + + @TestTargetNew( + level = TestLevel.COMPLETE, + notes = "", + method = "setID", + args = {java.lang.String.class} + ) + public void test_setIDLjava_lang_String() { + TimeZone tz = TimeZone.getTimeZone("GMT-6"); + assertEquals("GMT-06:00", tz.getID()); + tz.setID("New ID for GMT-6"); + assertEquals("New ID for GMT-6", tz.getID()); + } + + Locale loc = null; + + protected void setUp() { + loc = Locale.getDefault(); + Locale.setDefault(Locale.US); + } + + protected void tearDown() { + Locale.setDefault(loc); + } +} diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java index 0a2dbb5f..1ed3a11a 100644 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java +++ b/luni/src/test/java/org/apache/harmony/security/tests/java/security/KeyStore2Test.java @@ -310,7 +310,7 @@ public class KeyStore2Test extends junit.framework.TestCase { // testing for a certificate chain java.security.cert.Certificate cert2 = keyTest.getCertificate("alias2"); assertTrue("the certificate for alias2 is supposed to exist", - cert2 != null && cert2.equals(cert[0])); + cert2.equals(cert[0])); } diff --git a/luni/src/test/java/org/apache/harmony/security/tests/java/security/Security2Test.java b/luni/src/test/java/org/apache/harmony/security/tests/java/security/Security2Test.java index 13f83c17..75eeceba 100644 --- a/luni/src/test/java/org/apache/harmony/security/tests/java/security/Security2Test.java +++ b/luni/src/test/java/org/apache/harmony/security/tests/java/security/Security2Test.java @@ -17,11 +17,9 @@ package org.apache.harmony.security.tests.java.security; +import dalvik.annotation.TestLevel; import dalvik.annotation.TestTargetClass; import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; - import java.security.InvalidParameterException; import java.security.Provider; import java.security.Security; @@ -29,7 +27,6 @@ import java.util.Hashtable; import java.util.Iterator; import java.util.Map; import java.util.Set; - import tests.support.Support_ProviderTrust; import tests.support.Support_TestProvider; diff --git a/luni/src/test/java/tests/api/java/util/AllTests.java b/luni/src/test/java/tests/api/java/util/AllTests.java index 8a5e6b06..328bc8fe 100644 --- a/luni/src/test/java/tests/api/java/util/AllTests.java +++ b/luni/src/test/java/tests/api/java/util/AllTests.java @@ -71,7 +71,6 @@ public class AllTests { suite.addTestSuite(StringTokenizerTest.class); suite.addTestSuite(TimerTaskTest.class); suite.addTestSuite(TimerTest.class); - suite.addTestSuite(TimeZoneTest.class); suite.addTestSuite(TooManyListenersExceptionTest.class); suite.addTestSuite(VectorTest.class); suite.addTestSuite(WeakHashMapTest.class); diff --git a/luni/src/test/java/tests/api/java/util/TimeZoneTest.java b/luni/src/test/java/tests/api/java/util/TimeZoneTest.java deleted file mode 100644 index 035f8d1a..00000000 --- a/luni/src/test/java/tests/api/java/util/TimeZoneTest.java +++ /dev/null @@ -1,414 +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 tests.api.java.util; - -import dalvik.annotation.BrokenTest; -import dalvik.annotation.TestTargetNew; -import dalvik.annotation.TestTargets; -import dalvik.annotation.TestLevel; -import dalvik.annotation.TestTargetClass; -import dalvik.annotation.KnownFailure; -import dalvik.annotation.AndroidOnly; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.SimpleTimeZone; -import java.util.TimeZone; - -import tests.support.Support_Locale; -import tests.support.Support_TimeZone; - -@TestTargetClass(TimeZone.class) -public class TimeZoneTest extends junit.framework.TestCase { - - private static final int ONE_HOUR = 3600000; - - /** - * @tests java.util.TimeZone#getDefault() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDefault", - args = {} - ) - public void test_getDefault() { - assertNotSame("returns identical", - TimeZone.getDefault(), TimeZone.getDefault()); - } - - /** - * @tests java.util.TimeZone#getDSTSavings() - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDSTSavings", - args = {} - ) - public void test_getDSTSavings() { - // Test for method int java.util.TimeZone.getDSTSavings() - - // test on subclass SimpleTimeZone - TimeZone st1 = TimeZone.getTimeZone("America/New_York"); - assertEquals("T1A. Incorrect daylight savings returned", - ONE_HOUR, st1.getDSTSavings()); - - // a SimpleTimeZone with daylight savings different then 1 hour - st1 = TimeZone.getTimeZone("Australia/Lord_Howe"); - assertEquals("T1B. Incorrect daylight savings returned", - 1800000, st1.getDSTSavings()); - - // test on subclass Support_TimeZone, an instance with daylight savings - TimeZone tz1 = new Support_TimeZone(-5 * ONE_HOUR, true); - assertEquals("T2. Incorrect daylight savings returned", - ONE_HOUR, tz1.getDSTSavings()); - - // an instance without daylight savings - tz1 = new Support_TimeZone(3 * ONE_HOUR, false); - assertEquals("T3. Incorrect daylight savings returned, ", - 0, tz1.getDSTSavings()); - } - - /** - * @tests java.util.TimeZone#getOffset(long) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getOffset", - args = {long.class} - ) - public void test_getOffset_long() { - // Test for method int java.util.TimeZone.getOffset(long time) - - // test on subclass SimpleTimeZone - TimeZone st1 = TimeZone.getTimeZone("EST"); - long time1 = new GregorianCalendar(1998, Calendar.NOVEMBER, 11) - .getTimeInMillis(); - assertEquals("T1. Incorrect offset returned", - -(5 * ONE_HOUR), st1.getOffset(time1)); - - long time2 = new GregorianCalendar(1998, Calendar.JUNE, 11) - .getTimeInMillis(); -// Not working as expected on RI. -// st1 = TimeZone.getTimeZone("EST"); -// assertEquals("T2. Incorrect offset returned", -// -(4 * ONE_HOUR), st1.getOffset(time2)); - - // test on subclass Support_TimeZone, an instance with daylight savings - TimeZone tz1 = new Support_TimeZone(-5 * ONE_HOUR, true); - assertEquals("T3. Incorrect offset returned, ", - -(5 * ONE_HOUR), tz1.getOffset(time1)); - assertEquals("T4. Incorrect offset returned, ", - -(4 * ONE_HOUR), tz1.getOffset(time2)); - - // an instance without daylight savings - tz1 = new Support_TimeZone(3 * ONE_HOUR, false); - assertEquals("T5. Incorrect offset returned, ", - (3 * ONE_HOUR), tz1.getOffset(time1)); - assertEquals("T6. Incorrect offset returned, ", - (3 * ONE_HOUR), tz1.getOffset(time2)); - } - - /** - * @tests java.util.TimeZone#getTimeZone(java.lang.String) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getTimeZone", - args = {java.lang.String.class} - ) - public void test_getTimeZoneLjava_lang_String() { - assertEquals("Must return GMT when given an invalid TimeZone id SMT-8.", - "GMT", TimeZone.getTimeZone("SMT-8").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+28:70.", - "GMT", TimeZone.getTimeZone("GMT+28:70").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+28:30.", - "GMT", TimeZone.getTimeZone("GMT+28:30").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+8:70.", - "GMT", TimeZone.getTimeZone("GMT+8:70").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+3:.", - "GMT", TimeZone.getTimeZone("GMT+3:").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+3:0.", - "GMT", TimeZone.getTimeZone("GMT+3:0").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+2360.", - "GMT", TimeZone.getTimeZone("GMT+2360").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+892.", - "GMT", TimeZone.getTimeZone("GMT+892").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+082.", - "GMT", TimeZone.getTimeZone("GMT+082").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+28.", - "GMT", TimeZone.getTimeZone("GMT+28").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT+30.", - "GMT", TimeZone.getTimeZone("GMT+30").getID()); - assertEquals("Must return GMT when given TimeZone GMT.", - "GMT", TimeZone.getTimeZone("GMT").getID()); - assertEquals("Must return GMT when given TimeZone GMT+.", - "GMT", TimeZone.getTimeZone("GMT+").getID()); - assertEquals("Must return GMT when given TimeZone GMT-.", - "GMT", TimeZone.getTimeZone("GMT-").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT-8.45.", - "GMT", TimeZone.getTimeZone("GMT-8.45").getID()); - assertEquals("Must return GMT when given an invalid TimeZone time GMT-123:23.", - "GMT", TimeZone.getTimeZone("GMT-123:23").getID()); - assertEquals("Must return proper GMT formatted string for GMT+8:30 (eg. GMT+08:20).", - "GMT+08:30", TimeZone.getTimeZone("GMT+8:30").getID()); - assertEquals("Must return proper GMT formatted string for GMT+3 (eg. GMT+08:20).", - "GMT+03:00", TimeZone.getTimeZone("GMT+3").getID()); - assertEquals("Must return proper GMT formatted string for GMT+3:02 (eg. GMT+08:20).", - "GMT+03:02", TimeZone.getTimeZone("GMT+3:02").getID()); - assertEquals("Must return proper GMT formatted string for GMT+2359 (eg. GMT+08:20).", - "GMT+23:59", TimeZone.getTimeZone("GMT+2359").getID()); - assertEquals("Must return proper GMT formatted string for GMT+520 (eg. GMT+08:20).", - "GMT+05:20", TimeZone.getTimeZone("GMT+520").getID()); - assertEquals("Must return proper GMT formatted string for GMT+052 (eg. GMT+08:20).", - "GMT+00:52", TimeZone.getTimeZone("GMT+052").getID()); - assertEquals("Must return proper GMT formatted string for GMT-0 (eg. GMT+08:20).", - "GMT-00:00", TimeZone.getTimeZone("GMT-0").getID()); - } - - /** - * @tests java.util.TimeZone#setDefault(java.util.TimeZone) - */ - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setDefault", - args = {java.util.TimeZone.class} - ) - @BrokenTest("Runner sets timezone before test, hence old value != default") - public void test_setDefaultLjava_util_TimeZone() { - TimeZone oldDefault = TimeZone.getDefault(); - TimeZone zone = new SimpleTimeZone(45, "TEST"); - TimeZone.setDefault(zone); - assertEquals("timezone not set", zone, TimeZone.getDefault()); - TimeZone.setDefault(null); - assertEquals("default not restored", - oldDefault, TimeZone.getDefault()); - } - - class Mock_TimeZone extends TimeZone { - @Override - public int getOffset(int era, int year, int month, int day, int dayOfWeek, int milliseconds) { - return 0; - } - - @Override - public int getRawOffset() { - return 0; - } - - @Override - public boolean inDaylightTime(Date date) { - return false; - } - - @Override - public void setRawOffset(int offsetMillis) { - - } - - @Override - public boolean useDaylightTime() { - return false; - } - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "TimeZone", - args = {} - ) - public void test_constructor() { - assertNotNull(new Mock_TimeZone()); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "clone", - args = {} - ) - public void test_clone() { - TimeZone tz1 = TimeZone.getDefault(); - TimeZone tz2 = (TimeZone)tz1.clone(); - - assertTrue(tz1.equals(tz2)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getAvailableIDs", - args = {} - ) - public void test_getAvailableIDs() { - String[] str = TimeZone.getAvailableIDs(); - assertNotNull(str); - assertTrue(str.length != 0); - for(int i = 0; i < str.length; i++) { - assertNotNull(TimeZone.getTimeZone(str[i])); - } - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getAvailableIDs", - args = {int.class} - ) - public void test_getAvailableIDsI() { - String[] str = TimeZone.getAvailableIDs(0); - assertNotNull(str); - assertTrue(str.length != 0); - for(int i = 0; i < str.length; i++) { - assertNotNull(TimeZone.getTimeZone(str[i])); - } - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDisplayName", - args = {} - ) - public void test_getDisplayName() { - TimeZone tz = TimeZone.getTimeZone("GMT-6"); - assertEquals("GMT-06:00", tz.getDisplayName()); - tz = TimeZone.getTimeZone("America/Los_Angeles"); - assertEquals("Pacific Standard Time", tz.getDisplayName()); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDisplayName", - args = {java.util.Locale.class} - ) - public void test_getDisplayNameLjava_util_Locale() { - Locale[] requiredLocales = {Locale.US, Locale.FRANCE}; - if (!Support_Locale.areLocalesAvailable(requiredLocales)) { - // locale dependent test, bug 1943269 - return; - } - TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); - assertEquals("Pacific Standard Time", tz.getDisplayName(new Locale("US"))); - // BEGIN android-note: RI has "Heure", CLDR/ICU has "heure". - assertEquals("heure normale du Pacifique", tz.getDisplayName(Locale.FRANCE)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDisplayName", - args = {boolean.class, int.class} - ) - public void test_getDisplayNameZI() { - TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); - assertEquals("PST", tz.getDisplayName(false, 0)); - assertEquals("Pacific Daylight Time", tz.getDisplayName(true, 1)); - assertEquals("Pacific Standard Time", tz.getDisplayName(false, 1)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getDisplayName", - args = {boolean.class, int.class, java.util.Locale.class} - ) - @AndroidOnly("fail on RI. See comment below") - public void test_getDisplayNameZILjava_util_Locale() { - Locale[] requiredLocales = {Locale.US, Locale.UK, Locale.FRANCE}; - if (!Support_Locale.areLocalesAvailable(requiredLocales)) { - // locale dependent test, bug 1943269 - return; - } - TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles"); - assertEquals("PST", tz.getDisplayName(false, 0, Locale.US)); - assertEquals("Pacific Daylight Time", tz.getDisplayName(true, 1, Locale.US)); - assertEquals("Pacific Standard Time", tz.getDisplayName(false, 1, Locale.UK)); - //RI fails on following line. RI always returns short time zone name as "PST" - assertEquals("UTC-08:00", tz.getDisplayName(false, 0, Locale.FRANCE)); - // BEGIN android-note: RI has "Heure", CLDR/ICU has "heure". - assertEquals("heure avanc\u00e9e du Pacifique", tz.getDisplayName(true, 1, Locale.FRANCE)); - assertEquals("heure normale du Pacifique", tz.getDisplayName(false, 1, Locale.FRANCE)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "getID", - args = {} - ) - public void test_getID() { - TimeZone tz = TimeZone.getTimeZone("GMT-6"); - assertEquals("GMT-06:00", tz.getID()); - tz = TimeZone.getTimeZone("America/Denver"); - assertEquals("America/Denver", tz.getID()); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "hasSameRules", - args = {java.util.TimeZone.class} - ) - public void test_hasSameRulesLjava_util_TimeZone() { - TimeZone tz1 = TimeZone.getTimeZone("America/Denver"); - TimeZone tz2 = TimeZone.getTimeZone("America/Phoenix"); - assertEquals(tz1.getDisplayName(false, 0), tz2.getDisplayName(false, 0)); - // Arizona doesn't observe DST. See http://phoenix.about.com/cs/weather/qt/timezone.htm - assertFalse(tz1.hasSameRules(tz2)); - assertFalse(tz1.hasSameRules(null)); - tz1 = TimeZone.getTimeZone("America/Montreal"); - tz2 = TimeZone.getTimeZone("America/New_York"); - assertEquals(tz1.getDisplayName(), tz2.getDisplayName()); - assertFalse(tz1.getID().equals(tz2.getID())); - assertTrue(tz2.hasSameRules(tz1)); - assertTrue(tz1.hasSameRules(tz1)); - } - - @TestTargetNew( - level = TestLevel.COMPLETE, - notes = "", - method = "setID", - args = {java.lang.String.class} - ) - public void test_setIDLjava_lang_String() { - TimeZone tz = TimeZone.getTimeZone("GMT-6"); - assertEquals("GMT-06:00", tz.getID()); - tz.setID("New ID for GMT-6"); - assertEquals("New ID for GMT-6", tz.getID()); - } - - Locale loc = null; - - protected void setUp() { - loc = Locale.getDefault(); - Locale.setDefault(Locale.US); - } - - protected void tearDown() { - Locale.setDefault(loc); - } -} diff --git a/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java b/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java index 4f1bb642..c43c46cf 100644 --- a/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java +++ b/support/src/test/java/org/apache/harmony/testframework/serialization/SerializationTest.java @@ -46,6 +46,7 @@ import java.util.HashSet; import junit.framework.Assert; import junit.framework.TestCase; +import libcore.base.Objects; /** * Framework for serialization testing. Subclasses only need to override @@ -113,7 +114,7 @@ public abstract class SerializationTest extends TestCase { @Override public void runBare() throws Throwable { - if (mode != null && mode.equals(SERIAL_REFERENCE_MODE)) { + if (Objects.equal(mode, SERIAL_REFERENCE_MODE)) { produceGoldenFiles(); } else { super.runBare(); -- 2.11.0