package testcode; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.io.InputStream; import org.eclipse.jdt.annotation.NonNull; import org.junit.Test; import org.junit.internal.runners.JUnit4ClassRunner; import org.junit.runner.RunWith; /** * Test to see if getResource can reach the resource file. */ @RunWith(JUnit4ClassRunner.class) public class GetResourcesTest { /** * * @return string read from resource file * @throws IOException */ @Test public void test1() throws IOException { final @NonNull InputStream stream = getClass() .getResourceAsStream("theresource.txt"); /* use inputstream directly, this is the bottom level mechanism * that should be supported */ int c; @NonNull String s = ""; while (true) { c = stream.read(); if (c == -1) break; s = s + Character.toChars(c)[0]; } assertEquals("ok1", s); } // /** // * // * @param args the arguments of the call. // * @throws IOException // */ // static public void main(String[] args) throws IOException { // new GetResourcesTest(); // } }