test/java/util/Formatter/Constructors.java
Print this page
*** 20,30 ****
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/* @test
! * @bug 4981811 4984465 5064492 6240171
* @summary Unit test for all constructors introduced by the formatter feature
*/
import java.io.*;
import java.util.*;
--- 20,30 ----
* 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
*/
import java.io.*;
import java.util.*;
*** 83,155 ****
fail(x.getMessage());
}
}
public static void main(String [] args) {
-
// Formatter()
! try {
! Formatter f = new Formatter();
pass();
out(f, StringBuilder.class);
locale(f);
} catch (Exception x) {
fail("new Formatter()", x);
}
// Formatter(Appendable a)
! try {
! Formatter f = new Formatter((Appendable) null);
pass();
out(f, StringBuilder.class);
locale(f);
} catch (Exception x) {
fail("new Formatter((Appendable)null)", x);
}
// Formatter(Locale l)
! try {
! Formatter f = new Formatter((Locale) null);
pass();
out(f, StringBuilder.class);
locale(f, null);
} catch (Exception x) {
fail("new Formatter((Locale)null)", x);
}
// Formatter(Appendable a, Locale l)
! try {
! Formatter f = new Formatter((Appendable) null, (Locale) null);
pass();
out(f, StringBuilder.class);
locale(f, null);
} catch (Exception x) {
fail("new Formatter((Appendable) null, (Locale) null)", x);
}
// Formatter(String fileName)
! try {
! Formatter f = new Formatter("foo");
pass();
out(f, BufferedWriter.class);
locale(f);
} catch (Exception x) {
fail("new Formatter(\"foo\")", x);
}
try {
! Formatter f = new Formatter((String)null);
fail("new Formatter((String)null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((String)null)", x);
}
// Formatter(String fileName, String csn)
! try {
! Formatter f = new Formatter("foo", "UTF-8");
pass();
out(f, BufferedWriter.class);
locale(f);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"UTF-8\")", x);
--- 83,148 ----
fail(x.getMessage());
}
}
public static void main(String [] args) {
// Formatter()
! try (Formatter f = new Formatter()) {
pass();
out(f, StringBuilder.class);
locale(f);
} catch (Exception x) {
fail("new Formatter()", x);
}
// Formatter(Appendable a)
! try (Formatter f = new Formatter((Appendable) null)) {
pass();
out(f, StringBuilder.class);
locale(f);
} catch (Exception x) {
fail("new Formatter((Appendable)null)", x);
}
// Formatter(Locale l)
! try (Formatter f = new Formatter((Locale) null)) {
pass();
out(f, StringBuilder.class);
locale(f, null);
} catch (Exception x) {
fail("new Formatter((Locale)null)", x);
}
// Formatter(Appendable a, Locale l)
! try (Formatter f = new Formatter((Appendable) null, (Locale) null)) {
pass();
out(f, StringBuilder.class);
locale(f, null);
} catch (Exception x) {
fail("new Formatter((Appendable) null, (Locale) null)", x);
}
// Formatter(String fileName)
! try (Formatter f = new Formatter("foo")) {
pass();
out(f, BufferedWriter.class);
locale(f);
} catch (Exception x) {
fail("new Formatter(\"foo\")", x);
}
try {
! new Formatter((String)null);
fail("new Formatter((String)null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((String)null)", x);
}
// Formatter(String fileName, String csn)
! try (Formatter f = new Formatter("foo", "UTF-8")) {
pass();
out(f, BufferedWriter.class);
locale(f);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"UTF-8\")", x);
*** 165,211 ****
}
try {
new Formatter(".", "bar");
fail("new Formatter(\".\", \"bar\")");
! } catch (FileNotFoundException x) {
pass();
} catch (Exception x) {
fail("new Formatter(\".\", \"bar\")", x);
}
// Formatter(String fileName, String csn, Locale l)
! try {
! Formatter f = new Formatter("foo", "ISO-8859-1", Locale.GERMANY);
pass();
out(f, BufferedWriter.class);
locale(f, Locale.GERMANY);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"ISO-8859-1\", Locale.GERMANY)", x);
}
! try {
! Formatter f = new Formatter("foo", "ISO-8859-1", null);
pass();
locale(f, null);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"ISO-8859-1\", null)", x);
}
// Formatter(File)
! try {
! Formatter f = new Formatter(new File("foo"));
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(new File(\"foo\")", x);
}
try {
! Formatter f = new Formatter((File)null);
fail("new Formatter((File)null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((File)null)", x);
--- 158,201 ----
}
try {
new Formatter(".", "bar");
fail("new Formatter(\".\", \"bar\")");
! } catch (FileNotFoundException|UnsupportedEncodingException x) {
pass();
} catch (Exception x) {
fail("new Formatter(\".\", \"bar\")", x);
}
// Formatter(String fileName, String csn, Locale l)
! try (Formatter f = new Formatter("foo", "ISO-8859-1", Locale.GERMANY)) {
pass();
out(f, BufferedWriter.class);
locale(f, Locale.GERMANY);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"ISO-8859-1\", Locale.GERMANY)", x);
}
! try (Formatter f = new Formatter("foo", "ISO-8859-1", null)) {
pass();
locale(f, null);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(\"foo\", \"ISO-8859-1\", null)", x);
}
// Formatter(File)
! try (Formatter f = new Formatter(new File("foo"))) {
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(new File(\"foo\")", x);
}
try {
! new Formatter((File)null);
fail("new Formatter((File)null)");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((File)null)", x);
*** 229,267 ****
pass();
} catch (Exception x) {
fail("new Formatter((PrintStream) null)", x);
}
! try {
! Formatter f = new Formatter(new PrintStream("foo"));
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);
}
! try {
! Formatter f = new Formatter(new PrintStream("foo"),
! Locale.JAPANESE);
pass();
locale(f, Locale.JAPANESE);
out(f, PrintStream.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\")", x);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\")", x);
}
! try {
// The cast here is necessary to avoid an ambiguity error
// between Formatter(Appendable a, Locale l)
// and Formatter(OutputStream os, String csn)
! Formatter f = new Formatter(new PrintStream("foo"),
! (String)null);
fail("new Formatter(new PrintStream(\"foo\"), (String)null)");
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
} catch (NullPointerException x) {
pass();
--- 219,254 ----
pass();
} catch (Exception x) {
fail("new Formatter((PrintStream) null)", x);
}
! try (Formatter f = new Formatter(new PrintStream("foo"))) {
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);
}
! try (Formatter f = new Formatter(new PrintStream("foo"),
! Locale.JAPANESE)) {
pass();
locale(f, Locale.JAPANESE);
out(f, PrintStream.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\")", x);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\")", x);
}
! try (PrintStream ps = new PrintStream("foo")) {
// The cast here is necessary to avoid an ambiguity error
// between Formatter(Appendable a, Locale l)
// and Formatter(OutputStream os, String csn)
! new Formatter(ps, (String)null);
fail("new Formatter(new PrintStream(\"foo\"), (String)null)");
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
} catch (NullPointerException x) {
pass();
*** 269,308 ****
fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), (String)null)", x);
}
- try {
// The cast here is necessary to avoid an ambiguity error
// between Formatter(Appendable a, Locale l)
// and Formatter(OutputStream os, String csn)
! Formatter f = new Formatter(new PrintStream("foo"),
! (Locale)null);
pass();
locale(f, null);
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);
}
! try {
! Formatter f = new Formatter(new PrintStream("foo"),
! Locale.KOREAN);
pass();
locale(f, Locale.KOREAN);
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);
}
! try {
! Formatter f = new Formatter(new PrintStream("foo"),
! "UTF-16BE", null);
pass();
locale(f, null);
out(f, BufferedWriter.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
--- 256,292 ----
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)
! try (Formatter f = new Formatter(new PrintStream("foo"),
! (Locale)null)) {
pass();
locale(f, null);
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);
}
! try (Formatter f = new Formatter(new PrintStream("foo"),
! Locale.KOREAN)) {
pass();
locale(f, Locale.KOREAN);
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);
}
! try (Formatter f = new Formatter(new PrintStream("foo"),
! "UTF-16BE", null)) {
pass();
locale(f, null);
out(f, BufferedWriter.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
*** 310,322 ****
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
}
! try {
! Formatter f = new Formatter(new PrintStream("foo"),
! "UTF-16BE", Locale.ITALIAN);
pass();
locale(f, Locale.ITALIAN);
out(f, BufferedWriter.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
--- 294,305 ----
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", null");
}
! try (Formatter f = new Formatter(new PrintStream("foo"),
! "UTF-16BE", Locale.ITALIAN)) {
pass();
locale(f, Locale.ITALIAN);
out(f, BufferedWriter.class);
} catch (FileNotFoundException x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-16BE\", Locale.ITALIAN");
*** 359,370 ****
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) null)", x);
}
! try {
! Formatter f = new Formatter((OutputStream) new PrintStream("foo"));
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter((OutputStream) new PrintStream(\"foo\")", x);
--- 342,352 ----
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) null)", x);
}
! try (Formatter f = new Formatter((OutputStream) new PrintStream("foo"))) {
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter((OutputStream) new PrintStream(\"foo\")", x);
*** 378,408 ****
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) null, \"ISO-8859-1\")", x);
}
! try {
! new Formatter((OutputStream) new PrintStream("foo"), null);
fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null",
x);
}
! try {
! new Formatter(new PrintStream("foo"), "bar");
fail("new Formatter(new PrintStream(\"foo\"), \"bar\")");
} catch (UnsupportedEncodingException x) {
pass();
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"bar\")", x);
}
! try {
! Formatter f = new Formatter(new PrintStream("foo"), "UTF-8");
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\")", x);
--- 360,389 ----
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) null, \"ISO-8859-1\")", x);
}
! try (PrintStream ps = new PrintStream("foo")) {
! new Formatter((OutputStream) ps, null);
fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null");
} catch (NullPointerException x) {
pass();
} catch (Exception x) {
fail("new Formatter((OutputStream) new PrintStream(\"foo\"), null",
x);
}
! try (PrintStream ps = new PrintStream("foo")) {
! new Formatter(ps, "bar");
fail("new Formatter(new PrintStream(\"foo\"), \"bar\")");
} catch (UnsupportedEncodingException x) {
pass();
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"bar\")", x);
}
! try (Formatter f = new Formatter(new PrintStream("foo"), "UTF-8")) {
pass();
locale(f);
out(f, BufferedWriter.class);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\")", x);
*** 417,460 ****
} catch (Exception x) {
fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)",
x);
}
! try {
! new Formatter(new PrintStream("foo"), null, Locale.UK);
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);
}
! try {
! new Formatter(new PrintStream("foo"), "bar", Locale.UK);
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);
}
! try {
! Formatter f
! = new Formatter(new PrintStream("foo"), "UTF-8", Locale.UK);
pass();
out(f, BufferedWriter.class);
locale(f, Locale.UK);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\"), Locale.UK",
x);
}
// PrintStream(String fileName)
! try {
! new PrintStream("foo");
pass();
} catch (Exception x) {
fail("new PrintStream(\"foo\")", x);
}
--- 398,438 ----
} catch (Exception x) {
fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)",
x);
}
! try (PrintStream ps = new PrintStream("foo")) {
! new Formatter(ps, null, Locale.UK);
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);
}
! try (PrintStream ps = new PrintStream("foo")) {
! new Formatter(ps, "bar", Locale.UK);
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);
}
! try (Formatter f = new Formatter(new PrintStream("foo"), "UTF-8", Locale.UK)) {
pass();
out(f, BufferedWriter.class);
locale(f, Locale.UK);
} catch (Exception x) {
fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\"), Locale.UK",
x);
}
// PrintStream(String fileName)
! try (PrintStream ps = new PrintStream("foo")) {
pass();
} catch (Exception x) {
fail("new PrintStream(\"foo\")", x);
}
*** 467,478 ****
} catch (Exception x) {
fail("new PrintStream(\"foo\", null)", x);
}
// PrintStream(File file)
! try {
! new PrintStream(new File("foo"));
pass();
} catch (Exception x) {
fail("new PrintStream(new File(\"foo\"))", x);
}
--- 445,455 ----
} catch (Exception x) {
fail("new PrintStream(\"foo\", null)", x);
}
// PrintStream(File file)
! try (PrintStream ps = new PrintStream(new File("foo"))) {
pass();
} catch (Exception x) {
fail("new PrintStream(new File(\"foo\"))", x);
}
*** 485,496 ****
} catch (Exception x) {
fail("new PrintStream(new File(\"foo\"), null)", x);
}
// PrintWriter(String fileName)
! try {
! new PrintWriter("foo");
pass();
} catch (Exception x) {
fail("new PrintWriter(\"foo\")", x);
}
--- 462,472 ----
} catch (Exception x) {
fail("new PrintStream(new File(\"foo\"), null)", x);
}
// PrintWriter(String fileName)
! try (PrintWriter pw = new PrintWriter("foo")) {
pass();
} catch (Exception x) {
fail("new PrintWriter(\"foo\")", x);
}
*** 503,514 ****
} catch (Exception x) {
fail("new PrintWriter(\"foo\"), null", x);
}
// PrintWriter(File file)
! try {
! new PrintWriter(new File("foo"));
pass();
} catch (Exception x) {
fail("new PrintWriter(new File(\"foo\"))", x);
}
--- 479,489 ----
} catch (Exception x) {
fail("new PrintWriter(\"foo\"), null", x);
}
// PrintWriter(File file)
! try (PrintWriter pw = new PrintWriter(new File("foo"))) {
pass();
} catch (Exception x) {
fail("new PrintWriter(new File(\"foo\"))", x);
}