1
2
3
4
5 package com.jcabi.xml;
6
7 import java.io.ByteArrayInputStream;
8 import java.io.File;
9 import java.io.InputStream;
10 import java.nio.charset.StandardCharsets;
11 import java.nio.file.Files;
12 import org.cactoos.io.TeeInput;
13 import org.cactoos.scalar.LengthOf;
14 import org.hamcrest.MatcherAssert;
15 import org.hamcrest.Matchers;
16 import org.junit.jupiter.api.Test;
17
18
19
20
21
22
23 final class TextResourceTest {
24
25 @Test
26 void readsStreamAsText() {
27 final String text = "Blah!\u20ac\u2122";
28 final InputStream stream = new ByteArrayInputStream(
29 text.getBytes(StandardCharsets.UTF_8)
30 );
31 MatcherAssert.assertThat(
32 "Text does not match, but it should",
33 new TextResource(stream).toString(),
34 Matchers.is(text)
35 );
36 }
37
38 @Test
39 void readsFileAsText() throws Exception {
40 final String text = "<a xmlns='urn:foo'><b>\u0433!</b></a>";
41 final File file = Files.createTempDirectory("")
42 .resolve("dummy.xml").toFile();
43 new LengthOf(new TeeInput(text, file)).value();
44 MatcherAssert.assertThat(
45 "Text does not match, but it should",
46 new TextResource(file).toString(),
47 Matchers.is(text)
48 );
49 }
50
51 }