diff --git a/test/jdk/java/util/prefs/ExportSubtree.java b/test/jdk/java/util/prefs/ExportSubtree.java index c26e578ada1..3394139ea57 100644 --- a/test/jdk/java/util/prefs/ExportSubtree.java +++ b/test/jdk/java/util/prefs/ExportSubtree.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2019, 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 @@ -21,76 +21,74 @@ * questions. */ +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.util.prefs.Preferences; -/* @test - * @bug 6203576 4700020 7197662 +/** + * @test + * @bug 6203576 4700020 7197662 8217777 * @summary checks if the output of exportSubtree() is identical to * the output from previous release. * @run main/othervm -Djava.util.prefs.userRoot=. ExportSubtree */ - -import java.io.*; -import java.util.prefs.*; - public class ExportSubtree { - public static void main(String[] args) throws Exception { - try - { - //File f = new File(System.getProperty("test.src", "."), "TestPrefs.xml"); - ByteArrayInputStream bais = new ByteArrayInputStream(importPrefs.getBytes("utf-8")); - Preferences.importPreferences(bais); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - Preferences.userRoot().node("testExportSubtree").exportSubtree(baos); - Preferences.userRoot().node("testExportSubtree").removeNode(); - if (!expectedResult.equals(baos.toString())) { - //System.out.print(baos.toString()); - //System.out.print(expectedResult); - throw new IOException("exportSubtree does not output expected result"); - } - } - catch( Exception e ) { - e.printStackTrace(); - } - } + private static final String LS = System.getProperty("line.separator"); - static String ls = System.getProperty("line.separator"); - static String importPrefs = - "" - + "" - + "" - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + " " - + ""; + private static final String IMPORT_PREFS = + "" + + "" + + "" + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + " " + + ""; - static String expectedResult = - "" - + ls + "" - + ls + "" - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + " " - + ls + "" + ls; + private static final String EXPECTED_RESULT = + "" + LS + + "" + LS + + "" + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + " " + LS + + "" + LS; + + public static void main(String[] args) throws Exception { + ByteArrayInputStream bais = new ByteArrayInputStream(IMPORT_PREFS.getBytes("utf-8")); + Preferences.importPreferences(bais); + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + Preferences.userRoot().node("testExportSubtree").exportSubtree(baos); + Preferences.userRoot().node("testExportSubtree").removeNode(); + if (!EXPECTED_RESULT.equals(baos.toString())) { + String errMsg = "Preferences::exportSubtree did not yield the expected result."; + System.out.println(errMsg + LS + + "Actual:" + LS + + baos + LS + + "Expected:" + LS + + EXPECTED_RESULT); + throw new RuntimeException(errMsg); + } + } }