/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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 4981811 4984465 5064492 6240171 7000511
* @summary Unit test for all constructors introduced by the formatter feature
*/
public class Constructors {
static void pass() {
pass++;
}
first = new RuntimeException(s);
fail++;
}
fail++;
}
}
try {
pass();
} catch (RuntimeException x) {
fail(x.getMessage());
}
}
try {
Appendable a = f.out();
if (!c.isInstance(a))
+ " != " + c.getName());
pass();
} catch (RuntimeException x) {
fail(x.getMessage());
}
}
// Formatter()
pass();
out(f, StringBuilder.class);
locale(f);
} catch (Exception x) {
fail("new Formatter()", x);
}
// Formatter(Appendable a)
pass();
out(f, StringBuilder.class);
locale(f);
} catch (Exception x) {
fail("new Formatter((Appendable)null)", x);
}
// Formatter(Locale l)
pass();
out(f, StringBuilder.class);
} catch (Exception x) {
fail("new Formatter((Locale)null)", x);
}
// Formatter(Appendable a, Locale l)
pass();
out(f, StringBuilder.class);
} catch (Exception x) {
fail("new Formatter((Appendable) null, (Locale) null)", x);
}
// Formatter(String fileName)
pass();
out(f, BufferedWriter.class);
locale(f);
} catch (Exception x) {
fail("new Formatter(\"foo\")", x);
}
try {
fail("new Formatter((String)null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((String)null)", x);
}
// Formatter(String fileName, String csn)
pass();
out(f, BufferedWriter.class);
locale(f);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"UTF-8\")", x);
}
try {
fail("new Formatter(\"foo\", \"bar\")");
} catch (UnsupportedEncodingException x) {
pass();
} catch (Exception x) {
fail("new Formatter(\"foo\", \"bar\")", x);
}
try {
fail("new Formatter(\".\", \"bar\")");
} catch (FileNotFoundException|UnsupportedEncodingException x) {
pass();
} catch (Exception x) {
fail("new Formatter(\".\", \"bar\")", x);
}
// Formatter(String fileName, String csn, Locale l)
pass();
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"ISO-8859-1\", Locale.GERMANY)", x);
}
pass();
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"ISO-8859-1\", null)", x);
}
// Formatter(File)
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(new File(\"foo\")", x);
}
try {
fail("new Formatter((File)null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((File)null)", x);
}
// Formatter(PrintStream ps)
try {
// ambiguity detected at compile-time
pass();
out(f, PrintStream.class);
locale(f);
} catch (Exception x) {
fail("new Formatter(System.out)", x);
}
try {
fail("new Formatter((PrintStream) null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((PrintStream) null)", x);
}
pass();
locale(f);
out(f, PrintStream.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\")", x);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\")", x);
}
pass();
out(f, PrintStream.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\")", x);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\")", x);
}
// The cast here is necessary to avoid an ambiguity error
// between Formatter(Appendable a, Locale l)
// and Formatter(OutputStream os, String csn)
fail("new Formatter(new PrintStream(\"foo\"), (String)null)");
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
} catch (NullPointerException x) {
pass();
} catch (UnsupportedEncodingException x) {
fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
}
// The cast here is necessary to avoid an ambiguity error
// between Formatter(Appendable a, Locale l)
// and Formatter(OutputStream os, String csn)
pass();
out(f, PrintStream.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), (Locale)null)", x);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), (Locale)null)", x);
}
pass();
out(f, PrintStream.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), Locale.KOREAN)", x);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), Locale.KOREAN)", x);
}
"UTF-16BE", null)) {
pass();
out(f, BufferedWriter.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
} catch (UnsupportedEncodingException x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
}
pass();
out(f, BufferedWriter.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
} catch (UnsupportedEncodingException x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
}
"ASCII" : "ISO-8859-1";
try {
new ByteArrayOutputStream(),
new ByteArrayOutputStream()
};
} else {
pass();
}
} else {
pass();
}
} catch (UnsupportedEncodingException x) {
}
// Formatter(OutputStream os)
try {
fail("new Formatter((OutputStream) null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) null)", x);
}
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter((OutputStream) new PrintStream(\"foo\")", x);
}
// Formatter(OutputStream os, String csn)
try {
fail("new Formatter((OutputStream) null, \"ISO-8859-1\")");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) null, \"ISO-8859-1\")", x);
}
fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null",
x);
}
fail("new Formatter(new PrintStream(\"foo\"), \"bar\")");
} catch (UnsupportedEncodingException x) {
pass();
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"bar\")", x);
}
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\")", x);
}
// Formatter(OutputStream os, String csn, Locale l)
try {
fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)",
x);
}
fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)",
x);
}
fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)");
} catch (UnsupportedEncodingException x) {
pass();
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)",
x);
}
pass();
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\"), Locale.UK",
x);
}
// PrintStream(String fileName)
pass();
} catch (Exception x) {
fail("new PrintStream(\"foo\")", x);
}
// PrintStream(String fileName, String csn)
try {
fail("new PrintStream(\"foo\", null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new PrintStream(\"foo\", null)", x);
}
// PrintStream(File file)
pass();
} catch (Exception x) {
fail("new PrintStream(new File(\"foo\"))", x);
}
// PrintStream(File file, String csn)
try {
fail("new PrintStream(new File(\"foo\"), null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new PrintStream(new File(\"foo\"), null)", x);
}
// PrintWriter(String fileName)
pass();
} catch (Exception x) {
fail("new PrintWriter(\"foo\")", x);
}
// PrintWriter(String fileName, String csn)
try {
fail("new PrintWriter(\"foo\"), null");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new PrintWriter(\"foo\"), null", x);
}
// PrintWriter(File file)
pass();
} catch (Exception x) {
fail("new PrintWriter(new File(\"foo\"))", x);
}
// PrintWriter(File file, String csn)
try {
fail("new PrintWriter(new File(\"foo\")), null");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new PrintWriter(new File(\"foo\")), null", x);
}
if (fail != 0)
else
}
}