/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.io.suite;

import java.io.IOException;
import java.io.Writer;
import java.util.function.Function;
import javax.annotation.Resource;
import net.ranides.assira.junit.TestContract;
import org.junit.Assert;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class WriterTester {
    
    @Resource(name = "writer.chars!")
    private Function<Writer, String> wc;
    
    @TestContract
    public void appendBasic(Writer writer) throws IOException {
        writer.append('H');
        writer.append("ello");
        writer.append(".. world...", 2, 8);
        
        writer.close();
		Assert.assertEquals("Hello world", wc.apply(writer));
    }
    
    @TestContract
    public void writeBasic(Writer writer) throws IOException {
        writer.write('H');
        writer.write("ello");
        writer.write(" wor".toCharArray());
        writer.write("....ld..", 4, 2);
        writer.write("-- EOF.....".toCharArray(), 2, 4);

        writer.close();
		Assert.assertEquals("Hello world EOF", wc.apply(writer));
    }

}
