Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions core/src/test/java/redradishes/ByteBufferBundleTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package redradishes;

import com.google.common.primitives.Bytes;
import com.pholser.junit.quickcheck.ForAll;
import org.junit.contrib.theories.Theories;
import org.junit.contrib.theories.Theory;
import org.junit.contrib.theories.suppliers.TestedOn;
import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import com.pholser.junit.quickcheck.generator.Only;
import org.junit.runner.RunWith;
import org.xnio.Buffers;
import org.xnio.ByteBufferPool;
Expand All @@ -23,11 +22,11 @@
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertTrue;

@RunWith(Theories.class)
@RunWith(JUnitQuickcheck.class)
public class ByteBufferBundleTest {
@Theory
public void writes(@ForAll byte[][] messages, @TestedOn(ints = {7, 10}) int writeChunk,
@TestedOn(ints = {7, 10, 13}) int readChunk) throws IOException {
@Property
public void writes(byte[][] messages, @Only({"7", "10"}) int writeChunk,
@Only({"7", "10", "13"}) int readChunk) throws IOException {
List<byte[]> receivedMessages = new ArrayList<>();

ByteBufferPool byteBufferPool = ByteBufferPool.SMALL_DIRECT;
Expand Down
65 changes: 36 additions & 29 deletions core/src/test/java/redradishes/decoder/BulkStringBuildersTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package redradishes.decoder;

import com.pholser.junit.quickcheck.ForAll;
import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.From;
import com.pholser.junit.quickcheck.generator.InRange;
import com.pholser.junit.quickcheck.generator.java.lang.Encoded;
import org.junit.Rule;
import org.junit.contrib.theories.DataPoints;
import org.junit.contrib.theories.Theories;
import org.junit.contrib.theories.Theory;
import org.junit.contrib.theories.suppliers.TestedOn;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import com.pholser.junit.quickcheck.generator.Only;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
Expand Down Expand Up @@ -39,75 +37,84 @@
import static redradishes.decoder.parser.TestUtil.parseReply;
import static redradishes.hamcrest.HasSameContentAs.hasSameContentAs;

@RunWith(Theories.class)
@RunWith(JUnitQuickcheck.class)
public class BulkStringBuildersTest {
@Rule
public final MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
private CharsetDecoder charsetDecoder;

@DataPoints
public static final Charset[] CHARSETS = {UTF_8, UTF_16BE, UTF_16LE};

@Theory
public void parsesCharSequences(@ForAll @From(Encoded.class) @Encoded.InCharset("ISO-8859-1") String value,
@TestedOn(ints = {1, 2, 3, 5, 10, 100, 1000}) int bufferSize) {
parsesCharSequences(value, bufferSize, ISO_8859_1);
@Property
public void parsesCharSequences(@From(Encoded.class) @Encoded.InCharset("ISO-8859-1") String value,
@Only({"1", "2", "3", "5", "10", "100", "1000"}) int bufferSize) {
assertParsesCharSequences(value, bufferSize, ISO_8859_1);
}

@Theory
public void parsesCharSequences(@ForAll String value, @TestedOn(ints = {4, 5, 6, 7, 10, 100, 1000}) int bufferSize,
Charset charset) {
@Property
public void parsesCharSequences(String value, @Only({"4", "5", "6", "7", "10", "100", "1000"}) int bufferSize,
@Only({"0", "1", "2"}) int charsetIndex) {
Charset charset = CHARSETS[charsetIndex];
assertParsesCharSequences(value, bufferSize, charset);
}

private void assertParsesCharSequences(String value, int bufferSize, Charset charset) {
ByteBuffer src = ByteBuffer.wrap(encodeBulkString(value.getBytes(charset)));
CharSequence actual =
parseReply(src, bufferSize, bulkStringReply(charSequence()), Function.identity(), assertNoFailure(),
charset.newDecoder());
assertThat(actual, hasSameContentAs(value));
}

@Theory
public void parsesStrings(@ForAll @From(Encoded.class) @Encoded.InCharset("ISO-8859-1") String value,
@TestedOn(ints = {1, 2, 3, 5, 10, 100, 1000}) int bufferSize) {
parsesStrings(value, bufferSize, ISO_8859_1);
@Property
public void parsesStrings(@From(Encoded.class) @Encoded.InCharset("ISO-8859-1") String value,
@Only({"1", "2", "3", "5", "10", "100", "1000"}) int bufferSize) {
assertParsesStrings(value, bufferSize, ISO_8859_1);
}

@Property
public void parsesStrings(String value, @Only({"4", "5", "6", "7", "10", "100", "1000"}) int bufferSize,
@Only({"0", "1", "2"}) int charsetIndex) {
Charset charset = CHARSETS[charsetIndex];
assertParsesStrings(value, bufferSize, charset);
}

@Theory
public void parsesStrings(@ForAll String value, @TestedOn(ints = {4, 5, 6, 7, 10, 100, 1000}) int bufferSize,
Charset charset) {
private void assertParsesStrings(String value, int bufferSize, Charset charset) {
ByteBuffer src = ByteBuffer.wrap(encodeBulkString(value.getBytes(charset)));
CharSequence actual = parseReply(src, bufferSize, bulkStringReply(string()), Function.identity(), assertNoFailure(),
charset.newDecoder());
assertThat(actual, equalTo(value));
}

@Theory
public void parsesIntegers(@ForAll int value, @TestedOn(ints = {1, 2, 3, 5, 10, 100, 1000}) int bufferSize) {
@Property
public void parsesIntegers(int value, @Only({"1", "2", "3", "5", "10", "100", "1000"}) int bufferSize) {
ByteBuffer src = ByteBuffer.wrap(encodeBulkString(Integer.toString(value).getBytes(US_ASCII)));
assertThat(
parseReply(src, bufferSize, bulkStringReply(integer()), Function.identity(), assertNoFailure(), charsetDecoder),
equalTo(value));
verifyZeroInteractions(charsetDecoder);
}

@Theory
public void parsesLongs(@ForAll long value, @TestedOn(ints = {1, 2, 3, 5, 10, 100, 1000}) int bufferSize) {
@Property
public void parsesLongs(long value, @Only({"1", "2", "3", "5", "10", "100", "1000"}) int bufferSize) {
ByteBuffer src = ByteBuffer.wrap(encodeBulkString(Long.toString(value).getBytes(US_ASCII)));
assertThat(
parseReply(src, bufferSize, bulkStringReply(_long()), Function.identity(), assertNoFailure(), charsetDecoder),
equalTo(value));
verifyZeroInteractions(charsetDecoder);
}

@Theory
public void parsesByteArrays(@ForAll byte[] value, @TestedOn(ints = {1, 2, 3, 5, 10, 100, 1000}) int bufferSize) {
@Property
public void parsesByteArrays(byte[] value, @Only({"1", "2", "3", "5", "10", "100", "1000"}) int bufferSize) {
ByteBuffer src = ByteBuffer.wrap(encodeBulkString(value));
assertThat(parseReply(src, bufferSize, bulkStringReply(byteArray()), Function.identity(), assertNoFailure(),
charsetDecoder), equalTo(value));
verifyZeroInteractions(charsetDecoder);
}

@Theory
public void allocatesCharBufferOfTheRightSize(@ForAll @InRange(minInt = 0, maxInt = 100_000_000) int length) {
@Property
public void allocatesCharBufferOfTheRightSize(@InRange(minInt = 0, maxInt = 100_000_000) int length) {
CharBuffer charBuffer = (CharBuffer) charSequence().create(length, UTF_8.newDecoder());
assertThat(charBuffer.length(), equalTo(length));
}
Expand Down
Loading