Examples of StreamHandler


Examples of java.util.logging.StreamHandler

   * Test close() when having sufficient privilege, and a record has been
   * written to the output stream.
   */
  public void testClose_SufficientPrivilege_NormalClose() {
    ByteArrayOutputStream aos = new MockOutputStream();
    StreamHandler h = new StreamHandler(aos, new MockFormatter());
    h.publish(new LogRecord(Level.SEVERE,
        "testClose_SufficientPrivilege_NormalClose msg"));
    h.close();
    assertEquals("close", CallVerificationStack.getInstance()
        .getCurrentSourceMethod());
    assertNull(CallVerificationStack.getInstance().pop());
    assertEquals("flush", CallVerificationStack.getInstance()
        .getCurrentSourceMethod());
    CallVerificationStack.getInstance().clear();
    assertTrue(aos.toString().endsWith("MockFormatter_Tail"));
    h.close();
  }
View Full Code Here

Examples of java.util.logging.StreamHandler

   * Test close() when having sufficient privilege, and an output stream that
   * always throws exceptions.
   */
  public void testClose_SufficientPrivilege_Exception() {
    ByteArrayOutputStream aos = new MockExceptionOutputStream();
    StreamHandler h = new StreamHandler(aos, new MockFormatter());
    h.publish(new LogRecord(Level.SEVERE,
        "testClose_SufficientPrivilege_Exception msg"));
    h.flush();
    h.close();
  }
View Full Code Here

Examples of java.util.logging.StreamHandler

   * Test close() when having sufficient privilege, and no record has been
   * written to the output stream.
   */
  public void testClose_SufficientPrivilege_DirectClose() {
    ByteArrayOutputStream aos = new MockOutputStream();
    StreamHandler h = new StreamHandler(aos, new MockFormatter());
    h.close();
    assertEquals("close", CallVerificationStack.getInstance()
        .getCurrentSourceMethod());
    assertNull(CallVerificationStack.getInstance().pop());
    assertEquals("flush", CallVerificationStack.getInstance()
        .getCurrentSourceMethod());
View Full Code Here

Examples of java.util.logging.StreamHandler

   */
  public void testClose_InsufficientPrivilege() {
    SecurityManager oldMan = System.getSecurityManager();
    System.setSecurityManager(new MockSecurityManager());
    try {
      StreamHandler h = new StreamHandler(new ByteArrayOutputStream(),
          new MockFormatter());
      h.close();
      fail("Should throw SecurityException!");
    } catch (SecurityException e) {
      // expected
    } finally {
      System.setSecurityManager(oldMan);
View Full Code Here

Examples of java.util.logging.StreamHandler

  /*
   * Test close() when having no output stream.
   */
  public void testClose_NoOutputStream() {
    StreamHandler h = new StreamHandler();
    h.close();
  }
View Full Code Here

Examples of java.util.logging.StreamHandler

  /*
   * Test flush().
   */
  public void testFlush_Normal() {
    ByteArrayOutputStream aos = new MockOutputStream();
    StreamHandler h = new StreamHandler(aos, new MockFormatter());
    h.flush();
    assertEquals("flush", CallVerificationStack.getInstance()
        .getCurrentSourceMethod());
    assertNull(CallVerificationStack.getInstance().pop());
    CallVerificationStack.getInstance().clear();
  }
View Full Code Here

Examples of java.util.logging.StreamHandler

  /*
   * Test flush() when having no output stream.
   */
  public void testFlush_NoOutputStream() {
    StreamHandler h = new StreamHandler();
    h.flush();
  }
View Full Code Here

Examples of java.util.logging.StreamHandler

  /*
   * Test isLoggable(), use no filter, having output stream
   */
  public void testIsLoggable_NoOutputStream() {
    StreamHandler h = new StreamHandler();
    LogRecord r = new LogRecord(Level.INFO, null);
    assertFalse(h.isLoggable(r));

    h.setLevel(Level.WARNING);
    assertFalse(h.isLoggable(r));

    h.setLevel(Level.CONFIG);
    assertFalse(h.isLoggable(r));

    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    assertFalse(h.isLoggable(r));
  }
View Full Code Here

Examples of java.util.logging.StreamHandler

  /*
   * Test isLoggable(), use no filter, having output stream
   */
  public void testIsLoggable_NoFilter() {
    StreamHandler h = new StreamHandler(new ByteArrayOutputStream(),
        new SimpleFormatter());
    LogRecord r = new LogRecord(Level.INFO, null);
    assertTrue(h.isLoggable(r));

    h.setLevel(Level.WARNING);
    assertFalse(h.isLoggable(r));

    h.setLevel(Level.CONFIG);
    assertTrue(h.isLoggable(r));

    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    assertFalse(h.isLoggable(r));
  }
View Full Code Here

Examples of java.util.logging.StreamHandler

  /*
   * Test isLoggable(), use a filter, having output stream
   */
  public void testIsLoggable_WithFilter() {
    StreamHandler h = new StreamHandler(new ByteArrayOutputStream(),
        new SimpleFormatter());
    LogRecord r = new LogRecord(Level.INFO, null);
    h.setFilter(new MockFilter());
    assertFalse(h.isLoggable(r));
    assertSame(r, CallVerificationStack.getInstance().pop());

    h.setLevel(Level.CONFIG);
    assertFalse(h.isLoggable(r));
    assertSame(r, CallVerificationStack.getInstance().pop());

    h.setLevel(Level.WARNING);
    assertFalse(h.isLoggable(r));
    assertTrue(CallVerificationStack.getInstance().empty());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.