Path: blob/master/test/jdk/java/awt/Desktop/8064934/bug8064934.java
41152 views
/*1* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24* @bug 806493425* @key headful26* @requires (os.family == "windows")27* @summary Incorrect Exception message from java.awt.Desktop.open()28* @author Dmitry Markov29* @library /test/lib30* @modules java.desktop/sun.awt31* @build jdk.test.lib.Platform32* @run main bug806493433*/34import jdk.test.lib.Platform;35import java.awt.*;36import java.io.File;37import java.io.IOException;38import java.security.AccessController;39import java.security.PrivilegedAction;4041public class bug8064934 {42private static final String NO_ASSOCIATION_ERROR_MESSAGE = "Error message: No application is associated with" +43" the specified file for this operation.";4445public static void main(String[] args) {46// This test is intended only for Windows47if (!AccessController.doPrivileged((PrivilegedAction<Boolean>) Platform::isWindows)) {48System.out.println("The test is for Windows platform only");49return;50}5152// Test whether Desktop is supported of not53if (!Desktop.isDesktopSupported()) {54System.out.println("Desktop is not supported");55return;56}5758Desktop desktop = Desktop.getDesktop();59// Test whether open action is supported or not60if (!desktop.isSupported(Desktop.Action.OPEN)) {61System.out.println("Desktop.Action.OPEN is not supported");62return;63}6465File file = null;66try {67file = File.createTempFile("test", ".foo");68if (!file.exists()) {69throw new RuntimeException("Can not create temp file");70}71desktop.open(file);72} catch (IOException ioe) {73String errorMessage = ioe.getMessage().trim();74if (errorMessage != null && !errorMessage.endsWith(NO_ASSOCIATION_ERROR_MESSAGE)) {75throw new RuntimeException("Test FAILED! Wrong Error message: \n" +76"Actual " + errorMessage.substring(errorMessage.indexOf("Error message:")) + "\n" +77"Expected " + NO_ASSOCIATION_ERROR_MESSAGE);78}79} finally {80if (file != null) {81file.delete();82}83}8485System.out.println("Test PASSED!");86}87}888990