/*
 * The MIT License
 *
 * Copyright 2014 umireon.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package info.umireon.sw_library.systemtest;

import info.umireon.sw_library.SwLibraryMain;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.*;
import org.junit.Before;

/**
 *
 * @author umireon
 */
public class SwLibraryMainClassSystemTest {
    private final PipedOutputStream in = new PipedOutputStream();
    private final ByteArrayOutputStream out = new ByteArrayOutputStream();
    private InputStream oldIn;
    private PrintStream oldOut;

    @Before
    public void setup() throws IOException {
        oldIn = System.in;
        oldOut = System.out;

        System.setIn(new PipedInputStream(in));
        System.setOut(new PrintStream(out));
    }
    
    @After
    public void tearDown() {
        System.setIn(oldIn);
        System.setOut(oldOut);
    }
    
    @Test
    public void closedStdin() throws IOException {
        in.close();
        try {
            SwLibraryMain.main(new String[0]);
        } catch (IllegalArgumentException e) {
        }
        assertTrue(out.toString().contains("資料"));
    }
}

@@ -1401,24 +1401,52 @@
 rintStream;%0A
+import java.io.PrintWriter;%0A
 import org.j
@@ -2403,11 +2403,300 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void normalOperation() throws IOException %7B%0A        PrintWriter writer = new PrintWriter(in, true);%0A        writer.println(%22user1%22);%0A        writer.println(%22book1%22);%0A%0A        SwLibraryMain.main(new String%5B0%5D);%0A        assertTrue(out.toString().contains(%22%E8%B3%87%E6%96%99%22));%0A    %7D
 %0A%7D%0A

Test Normal Execution of System.