Rev | Line | |
---|
[896] | 1 | package testcode;
|
---|
| 2 |
|
---|
| 3 | import static org.junit.Assert.assertEquals;
|
---|
| 4 |
|
---|
| 5 | import java.io.IOException;
|
---|
| 6 | import java.io.InputStream;
|
---|
| 7 |
|
---|
| 8 | import org.eclipse.jdt.annotation.NonNull;
|
---|
| 9 | import org.junit.Test;
|
---|
| 10 | import org.junit.internal.runners.JUnit4ClassRunner;
|
---|
| 11 | import org.junit.runner.RunWith;
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * Test to see if getResource can reach the resource file.
|
---|
| 15 | */
|
---|
| 16 | @RunWith(JUnit4ClassRunner.class)
|
---|
| 17 | public class GetResourcesTest {
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | *
|
---|
| 21 | * @return string read from resource file
|
---|
| 22 | * @throws IOException
|
---|
| 23 | */
|
---|
| 24 | @Test
|
---|
| 25 | public void test1() throws IOException {
|
---|
[897] | 26 | final InputStream stream = getClass()
|
---|
[896] | 27 | .getResourceAsStream("theresource.txt");
|
---|
| 28 | /* use inputstream directly, this is the bottom level mechanism
|
---|
| 29 | * that should be supported
|
---|
| 30 | */
|
---|
| 31 | int c;
|
---|
| 32 | @NonNull
|
---|
| 33 | String s = "";
|
---|
| 34 | while (true) {
|
---|
| 35 | c = stream.read();
|
---|
| 36 | if (c == -1)
|
---|
| 37 | break;
|
---|
[1210] | 38 | // you can also use Character.toChars(c)[0];
|
---|
| 39 | s = s + (char) c;
|
---|
[896] | 40 | }
|
---|
| 41 | assertEquals("ok1", s);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.