Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: c1044ee8b4d31ce8f9919dfd70c0a95ebe6c7439 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*******************************************************************************
 * Copyright (c) 2011 SAP AG
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Lazar Kirchev, SAP AG - initial contribution
 ******************************************************************************/

package org.eclipse.equinox.console.common;

import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayOutputStream;

public class ConsoleOutputStreamTests {

    private static final int DATA_LENGTH = 4;

    @Test
    public void testWrite() throws Exception {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        ConsoleOutputStream out = new ConsoleOutputStream(byteOut);
        byte[] data = new byte[] { 'a', 'b', 'c', 'd' };
        for (byte b : data) {
            out.write(b);
        }
        out.flush();
        byte[] res = byteOut.toByteArray();

        Assert.assertNotNull("Bytes not written; result null", res);
        Assert.assertFalse("Bytes not written; result empty", res.length == 0);

        for (int i = 0; i < DATA_LENGTH; i++) {
            Assert.assertEquals("Wrong char read. Position " + i + ", expected " + data[i] + ", read " + res[i], data[i], res[i]);
        }
    }
}

Back to the top