Java Code Examples for java.util.logging.ConsoleHandler.close()

The following are Jave code examples for showing how to use close() of the java.util.logging.ConsoleHandler class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: j2objc   File: ConsoleHandlerTest.java   Source Code and License Vote up 6 votes
public void testClose_SufficientPrivilege_NormalClose() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.ConsoleHandler.formatter", className
			+ "$MockFormatter");
	LogManager.getLogManager().readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));
	ConsoleHandler h = new ConsoleHandler();
	h.publish(new LogRecord(Level.SEVERE,
			"testClose_SufficientPrivilege_NormalClose msg"));
	h.close();
	assertEquals("flush", CallVerificationStack.getInstance()
			.getCurrentSourceMethod());
	assertNull(CallVerificationStack.getInstance().pop());
	h.close();
}
 
Example 2
Project: j2objc   File: ConsoleHandlerTest.java   Source Code and License Vote up 6 votes
public void testClose_SufficientPrivilege_Exception() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.ConsoleHandler.formatter", className
			+ "$MockFormatter");
	LogManager.getLogManager().readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));
	ConsoleHandler h = new ConsoleHandler();

	h.publish(new LogRecord(Level.SEVERE,
			"testClose_SufficientPrivilege_Exception msg"));
	h.flush();
	h.close();
}
 
Example 3
Project: j2objc   File: ConsoleHandlerTest.java   Source Code and License Vote up 6 votes
public void testClose_SufficientPrivilege_DirectClose() throws Exception {
	Properties p = new Properties();
	p.put("java.util.logging.ConsoleHandler.formatter", className
			+ "$MockFormatter");
	LogManager.getLogManager().readConfiguration(
			EnvironmentHelper.PropertiesToInputStream(p));
	ConsoleHandler h = new ConsoleHandler();

	h.close();
	assertEquals("flush", CallVerificationStack.getInstance()
			.getCurrentSourceMethod());
	assertNull(CallVerificationStack.getInstance().pop());
	assertTrue(CallVerificationStack.getInstance().empty());
}
 
Example 4
Project: j2objc   File: ConsoleHandlerTest.java   Source Code and License Vote up 6 votes
public void testPublish_AfterClose() throws Exception {
	PrintStream backup = System.err;
	try {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		System.setErr(new PrintStream(bos));
		Properties p = new Properties();
		p.put("java.util.logging.ConsoleHandler.level", "FINE");
		p.put("java.util.logging.ConsoleHandler.formatter", className
				+ "$MockFormatter");
		LogManager.getLogManager().readConfiguration(
				EnvironmentHelper.PropertiesToInputStream(p));
		ConsoleHandler h = new ConsoleHandler();
		assertSame(h.getLevel(), Level.FINE);
		LogRecord r1 = new LogRecord(Level.INFO, "testPublish_Record1");
		LogRecord r2 = new LogRecord(Level.INFO, "testPublish_Record2");
		assertTrue(h.isLoggable(r1));
		h.publish(r1);
		assertTrue(bos.toString().indexOf("testPublish_Record1") >= 0);
		h.close();
		// assertFalse(h.isLoggable(r));
		assertTrue(h.isLoggable(r2));
		h.publish(r2);
		assertTrue(bos.toString().indexOf("testPublish_Record2") >= 0);
		h.flush();
		// assertEquals("MockFormatter_Head",
		// this.errSubstituteStream.toString());
	} catch (IOException e) {
		e.printStackTrace();
	} finally {
		System.setErr(backup);
	}
}