/* * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 4052976 7030649 * @summary Test URL.equals with anchors, and jar URLs
*/
if (url1.equals(url2)) thrownew RuntimeException("URL.equals fails with anchors"); if (url2.equals(url1)) thrownew RuntimeException("URL.equals fails with anchors"); if (url1.equals(null)) thrownew RuntimeException("URL.equals fails given null");
}
URL url1 = new URL(urlStr1);
URL url2 = new URL(urlStr2);
if (!url1.equals(url2)) {
System.out.println("Urls are not equal, so the test cannot run.");
System.out.println("url1: " + url1 + ", url2:" + url2); return 1;
}
URL jarUrl1 = new URL("jar:" + urlStr1 + entry1);
URL jarUrl2 = new URL("jar:" + urlStr2 + entry2);
jarUrl2.openConnection();
boolean equal = jarUrl1.equals(jarUrl2); if (expectEqual && !equal) {
System.out.println("URLs should be equal, but are not. " +
jarUrl1 + ", " + jarUrl2);
failed++;
} elseif (!expectEqual && equal) {
System.out.println("URLs should NOT be equal, but are. " +
jarUrl1 + ", " + jarUrl2);
failed++;
}
if (expectEqual) { // hashCode MUST produce the same integer result for equal urls int hash1 = jarUrl1.hashCode(); int hash2 = jarUrl2.hashCode(); if (hash1 != hash2) {
System.out.println("jarUrl1.hashCode = " + hash1);
System.out.println("jarUrl2.hashCode = " + hash2);
System.out.println("Equal urls should have same hashCode. " +
jarUrl1 + ", " + jarUrl2);
failed++;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.