use of org.cactoos.matchers.MatcherOf 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.matchers.MatcherOf 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.matchers.MatcherOf 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.matchers.MatcherOf 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));
}
use of org.cactoos.matchers.MatcherOf in project cactoos by yegor256.
the class SolidMapTest method mapsIterableWithKeyFuncAndValueFunc.
@Test
public void mapsIterableWithKeyFuncAndValueFunc() {
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<>("aa", "bb"));
MatcherAssert.assertThat("Functions are not applied to key and value", map, Matchers.allOf(Matchers.hasEntry(Matchers.equalTo("a"), Matchers.equalTo("AA")), Matchers.hasEntry(Matchers.equalTo("b"), Matchers.equalTo("BB")), new MatcherOf<>(m -> m.size() == 2)));
}
Aggregations