package org.koherent.datastore;

import static org.junit.Assert.fail;

import java.io.IOException;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.google.appengine.api.datastore.KeyFactory;
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

public class DatastoreInputStreamTest {
	private final LocalServiceTestHelper helper = new LocalServiceTestHelper(
			new LocalDatastoreServiceTestConfig());

	@Before
	public void setUp() {
		helper.setUp();
	}

	@After
	public void tearDown() {
		helper.tearDown();
	}

	@Test
	public void testConstructor() {
		try {
			new DatastoreInputStream(null);
			fail("Must throw an exception.");
		} catch (IllegalArgumentException e) {
		}
	}

	@Test
	public void testClose() {
		DatastoreInputStream in = new DatastoreInputStream(
				KeyFactory.createKey("kind", "name"));

		try {
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
			fail(e.getMessage());
		}

		try {
			in.read();
			fail("Must throw an exception.");
		} catch (IOException e) {
		}

		try {
			in.close();
			fail("Must throw an exception.");
		} catch (IOException e) {
		}
	}
}

@@ -57,20 +57,17 @@
 .Assert.
-fail
+*
 ;%0A%0Aimpor
@@ -1247,11 +1247,221 @@
 %7B%0A%09%09%7D%0A%09%7D
+%0A%0A%09@Test%0A%09public void testUnexisting() throws IOException %7B%0A%09%09DatastoreInputStream in = new DatastoreInputStream(%0A%09%09%09%09KeyFactory.createKey(%22kind%22, %22unexisting%22));%0A%09%09assertEquals(-1, in.read());%0A%09%09in.close();%0A%09%7D
 %0A%7D%0A

add DatastoreInputStreamTest#testUnexisting()