001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.security.tests.java.security;
019:
020: import java.net.URL;
021: import java.security.CodeSource;
022: import java.security.cert.Certificate;
023:
024: public class CodeSource2Test extends junit.framework.TestCase {
025:
026: /**
027: * @throws Exception
028: * @tests java.security.CodeSource#CodeSource(java.net.URL,
029: * java.security.cert.Certificate[])
030: */
031: public void test_ConstructorLjava_net_URL$Ljava_security_cert_Certificate()
032: throws Exception {
033: // Test for method java.security.CodeSource(java.net.URL,
034: // java.security.cert.Certificate [])
035: new CodeSource(new java.net.URL("file:///test"),
036: (Certificate[]) null);
037: }
038:
039: /**
040: * @tests java.security.CodeSource#equals(java.lang.Object)
041: */
042: public void test_equalsLjava_lang_Object() throws Exception {
043: // Test for method boolean
044: // java.security.CodeSource.equals(java.lang.Object)
045: CodeSource cs1 = new CodeSource(
046: new java.net.URL("file:///test"), (Certificate[]) null);
047: CodeSource cs2 = new CodeSource(
048: new java.net.URL("file:///test"), (Certificate[]) null);
049: assertTrue("Identical objects were not equal()!", cs1
050: .equals(cs2));
051: }
052:
053: /**
054: * @tests java.security.CodeSource#hashCode()
055: */
056: public void test_hashCode() throws Exception {
057: URL url = new java.net.URL("file:///test");
058: CodeSource cs = new CodeSource(url, (Certificate[]) null);
059: assertTrue("Did not get expected hashCode!",
060: cs.hashCode() == url.hashCode());
061: }
062:
063: /**
064: * @tests java.security.CodeSource#getCertificates()
065: */
066: public void test_getCertificates() throws Exception {
067: CodeSource cs = new CodeSource(
068: new java.net.URL("file:///test"), (Certificate[]) null);
069: assertNull("Should have gotten null certificate list.", cs
070: .getCertificates());
071: }
072:
073: /**
074: * @tests java.security.CodeSource#getLocation()
075: */
076: public void test_getLocation() throws Exception {
077: // Test for method java.net.URL java.security.CodeSource.getLocation()
078: CodeSource cs = new CodeSource(
079: new java.net.URL("file:///test"), (Certificate[]) null);
080: assertEquals("Did not get expected location!", "file:/test", cs
081: .getLocation().toString());
082: }
083:
084: /**
085: * @tests java.security.CodeSource#implies(java.security.CodeSource)
086: */
087: public void test_impliesLjava_security_CodeSource()
088: throws Exception {
089: // Test for method boolean
090: // java.security.CodeSource.implies(java.security.CodeSource)
091: CodeSource cs1 = new CodeSource(new URL("file:/d:/somedir"),
092: (Certificate[]) null);
093: CodeSource cs2 = new CodeSource(new URL("file:/d:/somedir/"),
094: (Certificate[]) null);
095: assertTrue("Does not add /", cs1.implies(cs2));
096:
097: cs1 = new CodeSource(new URL("file", null, -1, "/d:/somedir/"),
098: (Certificate[]) null);
099: cs2 = new CodeSource(new URL("file:/d:/somedir/"),
100: (Certificate[]) null);
101: assertTrue("null host should imply host", cs1.implies(cs2));
102: assertTrue("host should not imply null host", !cs2.implies(cs1));
103: }
104:
105: }
|