use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class BytesOfTest 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);
}
}), StandardCharsets.UTF_8).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 BytesOfTest method asBytesFromIterator.
@Test
void asBytesFromIterator() throws Exception {
final Text text = new TextOf("Good bye!");
new Assertion<>("Can't convert iterator into bytes", new BytesOf(new IteratorOfBytes(text)).asBytes(), new IsEqual<>(new BytesOf(text).asBytes())).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class BytesOfTest method readsLargeInMemoryContent.
@Test
void readsLargeInMemoryContent() throws Exception {
final int multiplier = 5_000;
final String body = "1234567890";
new Assertion<>("must read large content from in-memory Input", new BytesOf(new InputOf(new Concatenated(new HeadOf<>(multiplier, new Endless<>(new TextOf(body)))))).asBytes().length, new IsEqual<>(body.length() * multiplier)).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class TextTest method okForNoNulls.
@Test
void okForNoNulls() {
final String message = "Hello";
new Assertion<>("Must work with NoNulls", new NoNulls(new TextOf(message)), new IsText(message)).affirm();
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class ReaderOfTest method readsFile.
@Test
public void readsFile() throws Exception {
final String message = "file on äÄ üÜ öÖ ß жш";
final File input = this.folder.newFile();
Files.write(input.toPath(), message.getBytes(StandardCharsets.UTF_8));
new Assertion<>("Must read from file", new TextOf(new ReaderOf(input)), new IsText(message)).affirm();
}
Aggregations