Search in sources :

Example 21 with StreamHandler

use of java.util.logging.StreamHandler in project j2objc by google.

the class StreamHandlerTest method testClose_SufficientPrivilege_DirectClose.

/*
	 * 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());
    CallVerificationStack.getInstance().clear();
    assertEquals("MockFormatter_HeadMockFormatter_Tail", aos.toString());
}
Also used : StreamHandler(java.util.logging.StreamHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 22 with StreamHandler

use of java.util.logging.StreamHandler in project j2objc by google.

the class StreamHandlerTest method testConstructor_HasParameters_InvalidProperties.

/*
	 * Test the constructor with normal parameter, and invalid relevant log
	 * manager properties are set.
	 */
public void testConstructor_HasParameters_InvalidProperties() throws Exception {
    Properties p = new Properties();
    p.put("java.util.logging.StreamHandler.level", INVALID_LEVEL);
    p.put("java.util.logging.StreamHandler.filter", className + "");
    p.put("java.util.logging.StreamHandler.formatter", className + "");
    p.put("java.util.logging.StreamHandler.encoding", "XXXX");
    LogManager.getLogManager().readConfiguration(EnvironmentHelper.PropertiesToInputStream(p));
    assertEquals(INVALID_LEVEL, LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.level"));
    assertEquals("XXXX", LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.encoding"));
    StreamHandler h = new StreamHandler(new ByteArrayOutputStream(), new MockFormatter2());
    assertSame(Level.INFO, h.getLevel());
    assertTrue(h.getFormatter() instanceof MockFormatter2);
    assertNull(h.getFilter());
    assertNull(h.getEncoding());
}
Also used : StreamHandler(java.util.logging.StreamHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Properties(java.util.Properties)

Example 23 with StreamHandler

use of java.util.logging.StreamHandler in project j2objc by google.

the class StreamHandlerTest method testPublish_WithFilter.

/*
	 * Test publish(), use a filter, having output stream, normal log record.
	 */
public void testPublish_WithFilter() {
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    StreamHandler h = new StreamHandler(aos, new MockFormatter());
    h.setFilter(new MockFilter());
    LogRecord r = new LogRecord(Level.INFO, "testPublish_WithFilter");
    h.setLevel(Level.INFO);
    h.publish(r);
    h.flush();
    assertEquals("", aos.toString());
    assertSame(r, CallVerificationStack.getInstance().pop());
    h.setLevel(Level.WARNING);
    h.publish(r);
    h.flush();
    assertEquals("", aos.toString());
    assertTrue(CallVerificationStack.getInstance().empty());
    h.setLevel(Level.CONFIG);
    h.publish(r);
    h.flush();
    assertEquals("", aos.toString());
    assertSame(r, CallVerificationStack.getInstance().pop());
    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    h.publish(r);
    h.flush();
    assertEquals("", aos.toString());
    assertTrue(CallVerificationStack.getInstance().empty());
}
Also used : LogRecord(java.util.logging.LogRecord) StreamHandler(java.util.logging.StreamHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 24 with StreamHandler

use of java.util.logging.StreamHandler in project j2objc by google.

the class StreamHandlerTest method testSetEncoding_Unsupported.

/*
	 * Test setEncoding() methods with unsupported encoding.
	 */
public void testSetEncoding_Unsupported() {
    StreamHandler h = new StreamHandler();
    try {
        h.setEncoding("impossible");
        fail("Should throw UnsupportedEncodingException!");
    } catch (UnsupportedEncodingException e) {
    // expected
    }
    assertNull(h.getEncoding());
}
Also used : StreamHandler(java.util.logging.StreamHandler) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 25 with StreamHandler

use of java.util.logging.StreamHandler in project j2objc by google.

the class StreamHandlerTest method testConstructor_NoParameter_NoProperties.

/*
	 * Test the constructor with no parameter, and no relevant log manager
	 * properties are set.
	 */
public void testConstructor_NoParameter_NoProperties() {
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.level"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.filter"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.formatter"));
    assertNull(LogManager.getLogManager().getProperty("java.util.logging.StreamHandler.encoding"));
    StreamHandler h = new StreamHandler();
    assertSame(Level.INFO, h.getLevel());
    assertTrue(h.getFormatter() instanceof SimpleFormatter);
    assertNull(h.getFilter());
    assertNull(h.getEncoding());
}
Also used : StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter)

Aggregations

StreamHandler (java.util.logging.StreamHandler)41 ByteArrayOutputStream (java.io.ByteArrayOutputStream)25 SimpleFormatter (java.util.logging.SimpleFormatter)15 LogRecord (java.util.logging.LogRecord)14 Logger (java.util.logging.Logger)8 Properties (java.util.Properties)7 MockResponse (com.google.mockwebserver.MockResponse)6 HttpClient (org.apache.http.client.HttpClient)6 HttpGet (org.apache.http.client.methods.HttpGet)6 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)6 Handler (java.util.logging.Handler)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Level (java.util.logging.Level)1 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)1 Before (org.junit.Before)1 Test (org.junit.Test)1