384 try (Formatter f = new Formatter(new PrintStream("foo"), "UTF-8")) { 385 pass(); 386 locale(f); 387 out(f, BufferedWriter.class); 388 } catch (Exception x) { 389 fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\")", x); 390 } 391 392 // Formatter(OutputStream os, String csn, Locale l) 393 try { 394 new Formatter((OutputStream) null, "ISO-8859-1", Locale.UK); 395 fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)"); 396 } catch (NullPointerException x) { 397 pass(); 398 } catch (Exception x) { 399 fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)", 400 x); 401 } 402 403 try (PrintStream ps = new PrintStream("foo")) { 404 new Formatter(ps, null, Locale.UK); 405 fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)"); 406 } catch (NullPointerException x) { 407 pass(); 408 } catch (Exception x) { 409 fail("new Formatter(new PrintStream(\"foo\"), null, Locale.UK)", 410 x); 411 } 412 413 try (PrintStream ps = new PrintStream("foo")) { 414 new Formatter(ps, "bar", Locale.UK); 415 fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)"); 416 } catch (UnsupportedEncodingException x) { 417 pass(); 418 } catch (Exception x) { 419 fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)", 420 x); 421 } 422 423 try (Formatter f = new Formatter(new PrintStream("foo"), "UTF-8", Locale.UK)) { 424 pass(); 425 out(f, BufferedWriter.class); 426 locale(f, Locale.UK); 427 } catch (Exception x) { 428 fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\"), Locale.UK", 429 x); 430 } 431 432 // PrintStream(String fileName) 433 try (PrintStream ps = new PrintStream("foo")) { 434 pass(); 435 } catch (Exception x) { 436 fail("new PrintStream(\"foo\")", x); 437 } 438 439 // PrintStream(String fileName, String csn) 440 try { 441 new PrintStream("foo", null); 442 fail("new PrintStream(\"foo\", null)"); 443 } catch (NullPointerException x) { 444 pass(); 445 } catch (Exception x) { 446 fail("new PrintStream(\"foo\", null)", x); 447 } 448 449 // PrintStream(File file) 450 try (PrintStream ps = new PrintStream(new File("foo"))) { 451 pass(); 452 } catch (Exception x) { 453 fail("new PrintStream(new File(\"foo\"))", x); 454 } 455 456 // PrintStream(File file, String csn) 457 try { 458 new PrintStream(new File("foo"), null); 459 fail("new PrintStream(new File(\"foo\"), null)"); 460 } catch (NullPointerException x) { 461 pass(); 462 } catch (Exception x) { 463 fail("new PrintStream(new File(\"foo\"), null)", x); 464 } 465 466 // PrintWriter(String fileName) 467 try (PrintWriter pw = new PrintWriter("foo")) { 468 pass(); 469 } catch (Exception x) { 470 fail("new PrintWriter(\"foo\")", x); 471 } 472 473 // PrintWriter(String fileName, String csn) 474 try { 475 new PrintWriter("foo", null); 476 fail("new PrintWriter(\"foo\"), null"); 477 } catch (NullPointerException x) { 478 pass(); 479 } catch (Exception x) { 480 fail("new PrintWriter(\"foo\"), null", x); 481 } 482 483 // PrintWriter(File file) 484 try (PrintWriter pw = new PrintWriter(new File("foo"))) { 485 pass(); 486 } catch (Exception x) { 487 fail("new PrintWriter(new File(\"foo\"))", x); 488 } 489 490 // PrintWriter(File file, String csn) 491 try { 492 new PrintWriter(new File("foo"), null); 493 fail("new PrintWriter(new File(\"foo\")), null"); 494 } catch (NullPointerException x) { 495 pass(); 496 } catch (Exception x) { 497 fail("new PrintWriter(new File(\"foo\")), null", x); 498 } 499 500 if (fail != 0) 501 throw new RuntimeException((fail + pass) + " tests: " 502 + fail + " failure(s), first", first); 503 else 504 System.out.println("all " + (fail + pass) + " tests passed"); 505 } 506 } | 384 try (Formatter f = new Formatter(new PrintStream("foo"), "UTF-8")) { 385 pass(); 386 locale(f); 387 out(f, BufferedWriter.class); 388 } catch (Exception x) { 389 fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\")", x); 390 } 391 392 // Formatter(OutputStream os, String csn, Locale l) 393 try { 394 new Formatter((OutputStream) null, "ISO-8859-1", Locale.UK); 395 fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)"); 396 } catch (NullPointerException x) { 397 pass(); 398 } catch (Exception x) { 399 fail("new Formatter((OutputStream) null, \"ISO-8859-1\", Locale.UK)", 400 x); 401 } 402 403 try (PrintStream ps = new PrintStream("foo")) { 404 new Formatter(ps, (String)null, Locale.UK); 405 fail("new Formatter(new PrintStream(\"foo\"), (String)null, Locale.UK)"); 406 } catch (NullPointerException x) { 407 pass(); 408 } catch (Exception x) { 409 fail("new Formatter(new PrintStream(\"foo\"), (String)null, Locale.UK)", 410 x); 411 } 412 413 // Formatter(OutputStream os, Charset charset, Locale l) 414 try (PrintStream ps = new PrintStream("foo")) { 415 new Formatter(ps, (Charset)null, Locale.UK); 416 fail("new Formatter(new PrintStream(\"foo\"), (Charset)null, Locale.UK)"); 417 } catch (NullPointerException x) { 418 pass(); 419 } catch (Exception x) { 420 fail("new Formatter(new PrintStream(\"foo\"), (Charset)null, Locale.UK)", 421 x); 422 } 423 424 try (PrintStream ps = new PrintStream("foo")) { 425 new Formatter(ps, "bar", Locale.UK); 426 fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)"); 427 } catch (UnsupportedEncodingException x) { 428 pass(); 429 } catch (Exception x) { 430 fail("new Formatter(new PrintStream(\"foo\"), \"bar\", Locale.UK)", 431 x); 432 } 433 434 try (Formatter f = new Formatter(new PrintStream("foo"), "UTF-8", Locale.UK)) { 435 pass(); 436 out(f, BufferedWriter.class); 437 locale(f, Locale.UK); 438 } catch (Exception x) { 439 fail("new Formatter(new PrintStream(\"foo\"), \"UTF-8\"), Locale.UK", 440 x); 441 } 442 443 // PrintStream(String fileName) 444 try (PrintStream ps = new PrintStream("foo")) { 445 pass(); 446 } catch (Exception x) { 447 fail("new PrintStream(\"foo\")", x); 448 } 449 450 // PrintStream(String fileName, String csn) 451 try { 452 new PrintStream("foo", (String)null); 453 fail("new PrintStream(\"foo\", (String)null)"); 454 } catch (NullPointerException x) { 455 pass(); 456 } catch (Exception x) { 457 fail("new PrintStream(\"foo\", (String)null)", x); 458 } 459 460 // PrintStream(String fileName, Charset charset) 461 try { 462 new PrintStream("foo", (Charset)null); 463 fail("new PrintStream(\"foo\", (Charset)null)"); 464 } catch (NullPointerException x) { 465 pass(); 466 } catch (Exception x) { 467 fail("new PrintStream(\"foo\", (Charset)null)", x); 468 } 469 470 // PrintStream(File file) 471 try (PrintStream ps = new PrintStream(new File("foo"))) { 472 pass(); 473 } catch (Exception x) { 474 fail("new PrintStream(new File(\"foo\"))", x); 475 } 476 477 // PrintStream(File file, String csn) 478 try { 479 new PrintStream(new File("foo"), (String)null); 480 fail("new PrintStream(new File(\"foo\"), (String)null)"); 481 } catch (NullPointerException x) { 482 pass(); 483 } catch (Exception x) { 484 fail("new PrintStream(new File(\"foo\"), (String)null)", x); 485 } 486 487 // PrintStream(File file, Charset charset) 488 try { 489 new PrintStream(new File("foo"), (Charset)null); 490 fail("new PrintStream(new File(\"foo\"), (Charset)null)"); 491 } catch (NullPointerException x) { 492 pass(); 493 } catch (Exception x) { 494 fail("new PrintStream(new File(\"foo\"), (Charset)null)", x); 495 } 496 497 // PrintWriter(String fileName) 498 try (PrintWriter pw = new PrintWriter("foo")) { 499 pass(); 500 } catch (Exception x) { 501 fail("new PrintWriter(\"foo\")", x); 502 } 503 504 // PrintWriter(String fileName, String csn) 505 try { 506 new PrintWriter("foo", (String)null); 507 fail("new PrintWriter(\"foo\"), (String)null"); 508 } catch (NullPointerException x) { 509 pass(); 510 } catch (Exception x) { 511 fail("new PrintWriter(\"foo\"), (String)null", x); 512 } 513 514 // PrintWriter(String fileName, Charset charset) 515 try { 516 new PrintWriter("foo", (Charset)null); 517 fail("new PrintWriter(\"foo\"), (Charset)null"); 518 } catch (NullPointerException x) { 519 pass(); 520 } catch (Exception x) { 521 fail("new PrintWriter(\"foo\"), (Charset)null", x); 522 } 523 524 // PrintWriter(File file) 525 try (PrintWriter pw = new PrintWriter(new File("foo"))) { 526 pass(); 527 } catch (Exception x) { 528 fail("new PrintWriter(new File(\"foo\"))", x); 529 } 530 531 // PrintWriter(File file, String csn) 532 try { 533 new PrintWriter(new File("foo"), (String)null); 534 fail("new PrintWriter(new File(\"foo\")), (String)null"); 535 } catch (NullPointerException x) { 536 pass(); 537 } catch (Exception x) { 538 fail("new PrintWriter(new File(\"foo\")), (String)null", x); 539 } 540 541 // PrintWriter(File file, Charset charset) 542 try { 543 new PrintWriter(new File("foo"), (Charset)null); 544 fail("new PrintWriter(new File(\"foo\")), (Charset)null"); 545 } catch (NullPointerException x) { 546 pass(); 547 } catch (Exception x) { 548 fail("new PrintWriter(new File(\"foo\")), (Charset)null", x); 549 } 550 551 if (fail != 0) 552 throw new RuntimeException((fail + pass) + " tests: " 553 + fail + " failure(s), first", first); 554 else 555 System.out.println("all " + (fail + pass) + " tests passed"); 556 } 557 } |