Package org.apache.sling.scripting.core.impl

Examples of org.apache.sling.scripting.core.impl.LogWriter


public class LogWriterTest extends TestCase {

    public void testCharacter() {
        MockLogger logger = new MockLogger();
        LogWriter logWriter = new LogWriter(logger);

        // ensure logger is empty
        logger.getLastMessage();

        // empty flush
        logWriter.flush();
        String msg = logger.getLastMessage();
        assertNull(msg);

        // write a single character, message only after flush
        logWriter.write('a');
        assertNull(logger.getLastMessage());
        logWriter.flush();
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals("a", msg);

        // write a single CR, no message
        logWriter.write('\r');
        assertNull(logger.getLastMessage());

        // write a single LF, no message
        logWriter.write('\n');
        assertNull(logger.getLastMessage());

        // write three characters (one is CR)
        logWriter.write('a');
        logWriter.write('\r');
        logWriter.write('b');

        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals("a", msg);

        logWriter.flush();

        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals("b", msg);

        // write three characters (one is LF)
        logWriter.write('a');
        logWriter.write('\n');
        logWriter.write('b');

        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals("a", msg);

        logWriter.flush();

        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals("b", msg);
    }
View Full Code Here


        assertEquals("b", msg);
    }

    public void testStringCR() throws IOException {
        MockLogger logger = new MockLogger();
        LogWriter logWriter = new LogWriter(logger);
       
        // ensure logger is empty
        logger.getLastMessage();
       
        // empty flush
        logWriter.flush();
        String msg = logger.getLastMessage();
        assertNull(msg);
       
        // intermediate CR
        String tMsg1 = "Ein";
        String tMsg2 = "Text";
        String tMsg = tMsg1 + "\r" + tMsg2;
        logWriter.write(tMsg);
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg1, msg);
       
        logWriter.flush();
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg2, msg);
       
        // initial CR
        tMsg = "\r" + tMsg1 + tMsg2;
        logWriter.write(tMsg);
        msg = logger.getLastMessage();
        assertNull(msg);
       
        logWriter.flush();
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg1 + tMsg2, msg);
       
        // terminating CR
        tMsg = tMsg1 + tMsg2 + "\r";
        logWriter.write(tMsg);
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg1+tMsg2, msg);
       
        logWriter.flush();
        msg = logger.getLastMessage();
        assertNull(msg);
    }
View Full Code Here

        assertNull(msg);
    }
   
    public void testStringLF() throws IOException {
        MockLogger logger = new MockLogger();
        LogWriter logWriter = new LogWriter(logger);

        // ensure logger is empty
        logger.getLastMessage();

        // empty flush
        logWriter.flush();
        String msg = logger.getLastMessage();
        assertNull(msg);

        // intermediate LF
        String tMsg1 = "Ein";
        String tMsg2 = "Text";
        String tMsg = tMsg1 + "\n" + tMsg2;
        logWriter.write(tMsg);
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg1, msg);

        logWriter.flush();
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg2, msg);

        // initial LF
        tMsg = "\n" + tMsg1 + tMsg2;
        logWriter.write(tMsg);
        msg = logger.getLastMessage();
        assertNull(msg);

        logWriter.flush();
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg1 + tMsg2, msg);

        // terminating LF
        tMsg = tMsg1 + tMsg2 + "\n";
        logWriter.write(tMsg);
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg1+tMsg2, msg);

        logWriter.flush();
        msg = logger.getLastMessage();
        assertNull(msg);
    }
View Full Code Here

        assertNull(msg);
    }

    public void testString() throws IOException {
        MockLogger logger = new MockLogger();
        LogWriter logWriter = new LogWriter(logger);

        // ensure logger is empty
        logger.getLastMessage();

        // empty flush
        logWriter.flush();
        String msg = logger.getLastMessage();
        assertNull(msg);

        // flushed line
        String tMsg = "Ein Text";
        logWriter.write(tMsg);
        msg = logger.getLastMessage();
        assertNull(msg);

        logWriter.flush();
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg, msg);

        // CR terminated line
        logWriter.write(tMsg + "\r");
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg, msg);

        // LF terminated line
        logWriter.write(tMsg + "\n");
        msg = logger.getLastMessage();
        assertNotNull(msg);
        assertEquals(tMsg, msg);
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.scripting.core.impl.LogWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.