use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class BytesOfTest method closesInputStream.
@Test
public void closesInputStream() throws IOException {
final AtomicBoolean closed = new AtomicBoolean();
final InputStream input = new ByteArrayInputStream("how are you?".getBytes());
MatcherAssert.assertThat("Can't close InputStream correctly", 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 MatcherOf<>(text -> {
return closed.get();
}));
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class BytesOfTest method asBytes.
@Test
public void asBytes() throws IOException {
final Text text = new TextOf("Hello!");
MatcherAssert.assertThat("Can't convert text into bytes", new BytesOf(new InputOf(text)).asBytes(), Matchers.equalTo(new BytesOf(text.asString()).asBytes()));
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class WriterAsOutputStreamTest method writesLargeContentToFile.
@Test
public void writesLargeContentToFile() throws IOException {
final Path temp = Files.createTempFile("cactoos-1", "txt-1");
MatcherAssert.assertThat("Can't copy Input to Output and return Input", new TextOf(new TeeInput(new ResourceOf("org/cactoos/large-text.txt"), new OutputTo(new WriterAsOutputStream(new OutputStreamWriter(new FileOutputStream(temp.toFile()), StandardCharsets.UTF_8), StandardCharsets.UTF_8, // @checkstyle MagicNumber (1 line)
345)))), new TextHasString(new MatcherOf<>(str -> {
return new TextOf(temp).asString().equals(str);
})));
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class WriterAsOutputTest method writesLargeContentToFile.
@Test
public void writesLargeContentToFile() throws IOException {
final Path temp = Files.createTempFile("cactoos-1", "txt-1");
MatcherAssert.assertThat("Can't copy Input to Output and return Input", new TextOf(new TeeInput(new ResourceOf("org/cactoos/large-text.txt"), new WriterAsOutput(new OutputStreamWriter(new FileOutputStream(temp.toFile()), StandardCharsets.UTF_8)))), new TextHasString(new MatcherOf<>(str -> {
return new TextOf(temp).asString().equals(str);
})));
}
use of org.cactoos.text.TextOf in project cactoos by yegor256.
the class SolidMapTest method mapsEmptyIterableWithKeyFuncAndValueFunc.
@Test
public void mapsEmptyIterableWithKeyFuncAndValueFunc() {
final SolidMap<String, String> map = new SolidMap<>(key -> new SubText(new TextOf(key), 0, 1).asString(), value -> new UpperText(new TextOf(value)).asString(), new IterableOf<String>());
MatcherAssert.assertThat("Empty Iterable cannot be accepted for key and value mapping", map, new MatcherOf<>(m -> m.size() == 0));
}
Aggregations