use of org.cactoos.Text 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 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 in project cactoos by yegor256.
the class MappedWithIndexTest method failsIfIteratorExhausted.
@Test
void failsIfIteratorExhausted() {
final Iterator<Text> iterator = new MappedWithIndex<>((item, index) -> new FormattedText("%1$s X %2$s", index, item), new IterableOf<>("1").iterator());
iterator.next();
new Assertion<>("must throw NSEE", iterator::next, new Throws<>(NoSuchElementException.class)).affirm();
}
use of org.cactoos.Text in project cactoos by yegor256.
the class MappedWithIndexTest method removingElementsFromIterator.
@Test
void removingElementsFromIterator() {
final Iterator<Text> iterator = new MappedWithIndex<>((item, index) -> new FormattedText("%1$s : %2$s", index, item), new ArrayList<>(Arrays.asList("1", "2", "3")).iterator());
iterator.next();
iterator.remove();
new Assertion<>("must map values of changed iterator", new IterableOf<>(iterator), new HasValues<>(new TextOf("1 : 2"), new TextOf("2 : 3"))).affirm();
}
use of org.cactoos.Text in project cactoos by yegor256.
the class UncheckedBytesTest method worksNormallyWhenNoExceptionIsThrown.
@Test
void worksNormallyWhenNoExceptionIsThrown() throws Exception {
final Text source = new TextOf("hello, cactoos!");
new Assertion<>("Must work normally when no exception is thrown", new UncheckedBytes(new BytesOf(source)).asBytes(), new IsEqual<>(new BytesOf(source).asBytes())).affirm();
}
Aggregations