Search in sources :

Example 46 with PrintStream

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);
    }
}
Also used : PrintStream(java.io.PrintStream) NullOutputStream(org.apache.harmony.logging.tests.java.util.logging.HandlerTest.NullOutputStream)

Example 47 with PrintStream

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);
    }
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 48 with PrintStream

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();
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 49 with PrintStream

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();
}
Also used : PrintStream(java.io.PrintStream)

Example 50 with PrintStream

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();
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) ClassReader(org.objectweb.asm.ClassReader) ClassPrinter(org.springsource.loaded.test.infra.ClassPrinter)

Aggregations

PrintStream (java.io.PrintStream)1828 ByteArrayOutputStream (java.io.ByteArrayOutputStream)805 Test (org.junit.Test)583 File (java.io.File)331 IOException (java.io.IOException)295 FileOutputStream (java.io.FileOutputStream)207 ArrayList (java.util.ArrayList)89 FileNotFoundException (java.io.FileNotFoundException)83 OutputStream (java.io.OutputStream)81 Before (org.junit.Before)66 BufferedReader (java.io.BufferedReader)53 BufferedOutputStream (java.io.BufferedOutputStream)49 Map (java.util.Map)49 Date (java.util.Date)46 Path (org.apache.hadoop.fs.Path)42 UnsupportedEncodingException (java.io.UnsupportedEncodingException)41 InputStreamReader (java.io.InputStreamReader)38 Matchers.anyString (org.mockito.Matchers.anyString)38 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)36 List (java.util.List)35