use of java.io.PrintStream in project j2objc by google.
the class LogManagerTest method testGlobalPropertyConfig.
public void testGlobalPropertyConfig() throws Exception {
PrintStream err = System.err;
try {
System.setErr(new PrintStream(new NullOutputStream()));
// before add config property, root has two handler
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(2, manager.getLogger("").getHandlers().length);
// one valid config class
props.setProperty("config", className + "$MockValidConfig");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(3, manager.getLogger("").getHandlers().length);
// two config class take effect orderly
props.setProperty("config", className + "$MockValidConfig " + className + "$MockValidConfig2");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(2, manager.getLogger("").getHandlers().length);
props.setProperty("config", className + "$MockValidConfig2 " + className + "$MockValidConfig");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(3, manager.getLogger("").getHandlers().length);
// invalid config class which throw exception, just print exception
// and
// message
props.setProperty("config", className + "$MockInvalidConfigException");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
// invalid config class without default constructor, just print
// exception and message
props.setProperty("config", className + "$MockInvalidConfigNoDefaultConstructor");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
// bad config class name, just print exception and message
props.setProperty("config", "badname");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
// invalid separator, nothing happened
props.setProperty("config", className + "$MockValidConfig2;" + className + "$MockValidConfig");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(2, manager.getLogger("").getHandlers().length);
props.setProperty("config", className + "$MockValidConfig2;" + className + "$MockValidConfig " + className + "$MockValidConfig");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(3, manager.getLogger("").getHandlers().length);
// duplicate config class, take effect twice
props.setProperty("config", className + "$MockValidConfig " + className + "$MockValidConfig");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(4, manager.getLogger("").getHandlers().length);
// invalid config classes mixed with valid config classes, valid
// config
// classes take effect
props.setProperty("config", "badname " + className + "$MockValidConfig " + className + "$MockInvalidConfigNoDefaultConstructor " + className + "$MockValidConfig");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(4, manager.getLogger("").getHandlers().length);
// global property take effect before logger specified property
props.setProperty("config", className + "$MockValidConfig");
manager.readConfiguration(EnvironmentHelper.PropertiesToInputStream(props));
assertEquals(Level.FINE, manager.getLogger("").getLevel());
} finally {
System.setErr(err);
}
}
use of java.io.PrintStream in project j2objc by google.
the class UnicodeUtilsTest method testIllegalUnicodeEscapeSequence.
// Verify that a string with a Unicode escape that isn't a legal C99
// sequence is reported as an error.
public void testIllegalUnicodeEscapeSequence() {
PrintStream savedErrStream = System.err;
try {
System.setErr(new PrintStream(new ByteArrayOutputStream()));
String fragment = "abc�";
String escaped = UnicodeUtils.escapeStringLiteral(fragment);
assertErrorCount(1);
// Verify the unicode is emitted anyways (it's useful as a diagnostic).
assertEquals("abc\\udfff", escaped);
} finally {
System.setErr(savedErrStream);
}
}
use of java.io.PrintStream in project j2objc by google.
the class CycleFinderTest method printCyclesToString.
private String printCyclesToString() {
ByteArrayOutputStream cyclesOut = new ByteArrayOutputStream();
CycleFinder.printCycles(cycles, new PrintStream(cyclesOut));
return cyclesOut.toString();
}
use of java.io.PrintStream in project j2objc by google.
the class ConsoleHandlerTest method setUp.
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
errSubstituteStream = new MockOutputStream();
System.setErr(new PrintStream(errSubstituteStream));
LogManager.getLogManager().reset();
}
use of java.io.PrintStream in project spring-loaded by spring-projects.
the class SpringLoadedTests method printItAndReturnIt.
protected String printItAndReturnIt(byte[] classdata, boolean quoted) {
OutputStream os = new SimpleOutputStream();
ClassReader reader = new ClassReader(classdata);
reader.accept(new ClassPrinter(new PrintStream(os)), 0);
StringBuffer sb = new StringBuffer(os.toString().replace("\r", ""));
if (!quoted) {
return sb.toString();
}
for (int i = 0; i < sb.length(); i++) {
if (sb.charAt(i) == '\n') {
sb.insert(i + 1, "\"");
sb.insert(i, "\\n\"+");
i += 4;
}
}
sb.delete(sb.length() - 3, sb.length());
sb.insert(0, "\"");
return sb.toString();
}
Aggregations