Path: blob/master/test/jdk/java/lang/System/MacEncoding/ExpectedEncoding.java
41153 views
/*1* Copyright (c) 2012, 2017, 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/**24* Check that the value of file.encoding and sun.jnu.encoding match the expected25* values passed in on the command-line.26*/27public class ExpectedEncoding {28public static void main(String[] args) {29boolean failed = false;30if (args.length != 2) {31System.out.println("Usage:");32System.out.println("$ java ExpectedEncoding <expected file.encoding> <expected sun.jnu.encoding>");33System.out.println("$ use \"skip\" to skip checking property's value");34System.exit(1);35}36String expectFileEnc = args[0];37String expectSunJnuEnc = args[1];3839String fileEnc = System.getProperty("file.encoding");40String jnuEnc = System.getProperty("sun.jnu.encoding");4142if ("skip".equals(expectFileEnc)) {43System.err.println("Expected file.encoding is \"skip\", ignoring");44} else {45if (fileEnc == null || !fileEnc.equals(expectFileEnc)) {46System.err.println("Expected file.encoding: " + expectFileEnc);47System.err.println("Actual file.encoding: " + fileEnc);48failed = true;49}50}51if ("skip".equals(expectSunJnuEnc)) {52System.err.println("Expected sun.jnu.encoding is \"skip\", ignoring");53} else {54if (jnuEnc == null || !jnuEnc.equals(expectSunJnuEnc)) {55System.err.println("Expected sun.jnu.encoding: " + expectSunJnuEnc);56System.err.println("Actual sun.jnu.encoding: " + jnuEnc);57failed = true;58}59}6061if (failed) {62throw new RuntimeException("Test Failed");63}64}65}666768