Search in sources :

Example 11 with StreamHandler

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

the class StreamHandlerTest method testPublish_NullMsg.

/*
	 * Test publish(), a log record with null msg, having output stream
	 */
public void testPublish_NullMsg() {
    ByteArrayOutputStream aos = new ByteArrayOutputStream();
    StreamHandler h = new StreamHandler(aos, new MockFormatter());
    LogRecord r = new LogRecord(Level.INFO, null);
    h.publish(r);
    h.flush();
    assertEquals("MockFormatter_Head", aos.toString());
}
Also used : LogRecord(java.util.logging.LogRecord) StreamHandler(java.util.logging.StreamHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 12 with StreamHandler

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

the class StreamHandlerTest method testPublish_NoOutputStream.

/*
	 * Test publish(), use no filter, having output stream, normal log record.
	 */
public void testPublish_NoOutputStream() {
    StreamHandler h = new StreamHandler();
    LogRecord r = new LogRecord(Level.INFO, "testPublish_NoOutputStream");
    h.publish(r);
    h.setLevel(Level.WARNING);
    h.publish(r);
    h.setLevel(Level.CONFIG);
    h.publish(r);
    r.setLevel(Level.OFF);
    h.setLevel(Level.OFF);
    h.publish(r);
}
Also used : LogRecord(java.util.logging.LogRecord) StreamHandler(java.util.logging.StreamHandler)

Example 13 with StreamHandler

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

the class StreamHandlerTest method testIsLoggable_WithFilter.

/*
	 * 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());
}
Also used : LogRecord(java.util.logging.LogRecord) StreamHandler(java.util.logging.StreamHandler) SimpleFormatter(java.util.logging.SimpleFormatter) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 14 with StreamHandler

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

the class StreamHandlerTest method testClose_NoOutputStream.

/*
	 * Test close() when having insufficient privilege.
	 *
	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);
		}
	}

	/*
	 * Test close() when having no output stream.
	 */
public void testClose_NoOutputStream() {
    StreamHandler h = new StreamHandler();
    h.close();
}
Also used : StreamHandler(java.util.logging.StreamHandler)

Example 15 with StreamHandler

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

the class StreamHandlerTest method testFlush_NoOutputStream.

/*
	 * Test flush() when having no output stream.
	 */
public void testFlush_NoOutputStream() {
    StreamHandler h = new StreamHandler();
    h.flush();
}
Also used : StreamHandler(java.util.logging.StreamHandler)

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