Package batch.internal.support

Source Code of batch.internal.support.ResourceLineReaderTests

package batch.internal.support;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import junit.framework.TestCase;

import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;

import batch.InvalidBatchException;
import batch.internal.support.ResourceLineReader;

/**
*/
public class ResourceLineReaderTests extends TestCase {

  public void testBadResource() throws Exception {
    ResourceLineReader reader = new ResourceLineReader(new InputStreamResource(new InputStream() {
      public int read() throws IOException {
        throw new IOException("Foo");
      }
    }));
    try {
      reader.read();
      fail("Expected InvalidBatchException");
    } catch (InvalidBatchException e) {
      // expected
      assertTrue(e.getMessage().startsWith("Unable to read"));
    }
  }

  public void testRead() throws Exception {
    Resource resource = new InputStreamResource(new ByteArrayInputStream("a,b,c\n1,2,3".getBytes()));
    ResourceLineReader reader = new ResourceLineReader(resource);
    int count = 0;
    String line;
    while ((line = (String) reader.read()) != null) {
      count++;
      assertNotNull(line);
    }

    assertEquals(2, count);
  }
}
TOP

Related Classes of batch.internal.support.ResourceLineReaderTests

TOP
Copyright © 2018 www.massapi.com. 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.