use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class ReaderOfTest method readsUri.
@Test
public void readsUri() throws Exception {
final String message = "URI on äÄ üÜ öÖ ß жш";
final File input = this.folder.newFile();
Files.write(input.toPath(), message.getBytes(StandardCharsets.UTF_8));
new Assertion<>("Must read from uri", new TextOf(new ReaderOf(input.toURI())), new IsText(message)).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class InputOfTest method readsStringFromReader.
@Test
void readsStringFromReader() throws Exception {
final String source = "hello, source!";
new Assertion<>("must read string through a reader", new TextOf(new InputOf(new StringReader(source))), new IsText(source)).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class InputOfTest method closesInputStream.
@Test
void closesInputStream() throws Exception {
final AtomicBoolean closed = new AtomicBoolean();
final InputStream input = new ByteArrayInputStream("how are you?".getBytes());
new TextOf(new InputOf(new InputStream() {
@Override
public int read() throws IOException {
return input.read();
}
@Override
public void close() throws IOException {
input.close();
closed.set(true);
}
})).asString();
new Assertion<>("must close InputStream correctly", closed.get(), new IsTrue()).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class InputOfTest method readsEncodedStringFromReader.
@Test
void readsEncodedStringFromReader() throws Exception {
final String source = "hello, друг!";
new Assertion<>("must read encoded string through a reader", new TextOf(new BytesOf(new InputOf(new StringReader(source), StandardCharsets.UTF_8))), new IsText(source)).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class LoggingInputTest method logReadFromOneByte.
@Test
void logReadFromOneByte() throws Exception {
final Logger logger = new FakeLogger();
new LengthOf(new LoggingInput(new InputOf("a"), "memory", logger)).value();
new Assertion<>("Must log one byte read from memory", new TextOf(logger.toString()), new HasString("Read 1 byte(s) from memory in")).affirm();
}
Aggregations