Search in sources :

Example 6 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TailOfTest method failsIfBufferSizeSmallerThanTailSize.

@Test(expected = IllegalArgumentException.class)
public void failsIfBufferSizeSmallerThanTailSize() throws Exception {
    final int size = 4;
    new BytesOf(new TailOf(new InputOf(new BytesOf(this.generate(size))), size, size - 1)).asBytes();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) Test(org.junit.Test)

Example 7 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TailOfTest method tailsOnLongStream.

@Test
public void tailsOnLongStream() throws Exception {
    final int size = 4;
    final byte[] bytes = this.generate(size);
    new Assertion<>("Can't tail long stream", new BytesOf(new TailOf(new InputOf(new BytesOf(bytes)), size - 1)).asBytes(), new IsEqual<>(Arrays.copyOfRange(bytes, 1, bytes.length))).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Example 8 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TailOfTest method tailsOnShorterStream.

@Test
public void tailsOnShorterStream() throws Exception {
    final int size = 4;
    final byte[] bytes = this.generate(size);
    new Assertion<>("Can't tail shorter stream", new BytesOf(new TailOf(new InputOf(new BytesOf(bytes)), size + 1)).asBytes(), new IsEqual<>(bytes)).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Example 9 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TailOfTest method tailsOnExactStream.

@Test
public void tailsOnExactStream() throws Exception {
    final int size = 4;
    final byte[] bytes = this.generate(size);
    new Assertion<>("Can't tail exact stream", new BytesOf(new TailOf(new InputOf(new BytesOf(bytes)), size)).asBytes(), new IsEqual<>(bytes)).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Example 10 with BytesOf

use of org.cactoos.bytes.BytesOf in project cactoos by yegor256.

the class TailOfTest method tailsOnStreamLongerThanBufferAndBytes.

@Test
public void tailsOnStreamLongerThanBufferAndBytes() throws Exception {
    final int size = 4;
    final byte[] bytes = this.generate(size);
    new Assertion<>("Can't tail longer stream", new BytesOf(new TailOf(new InputOf(new BytesOf(bytes)), size - 1, size - 1)).asBytes(), new IsEqual<>(Arrays.copyOfRange(bytes, 1, bytes.length))).affirm();
}
Also used : BytesOf(org.cactoos.bytes.BytesOf) IsEqual(org.hamcrest.core.IsEqual) Test(org.junit.Test)

Aggregations

BytesOf (org.cactoos.bytes.BytesOf)17 Test (org.junit.Test)12 IsEqual (org.hamcrest.core.IsEqual)6 File (java.io.File)4 TextOf (org.cactoos.text.TextOf)4 Test (org.junit.jupiter.api.Test)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 LengthOf (org.cactoos.scalar.LengthOf)3 HasContent (org.llorllale.cactoos.matchers.HasContent)3 HasString (org.llorllale.cactoos.matchers.HasString)3 OutputStream (java.io.OutputStream)2 Logger (java.util.logging.Logger)2 AllOf (org.hamcrest.core.AllOf)2 StringContains (org.hamcrest.core.StringContains)2 EndsWith (org.llorllale.cactoos.matchers.EndsWith)2 IsText (org.llorllale.cactoos.matchers.IsText)2 StartsWith (org.llorllale.cactoos.matchers.StartsWith)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 StringReader (java.io.StringReader)1