use of org.junit.experimental.theories.Theory in project cryptomator by cryptomator.
the class AutoClosingLongStreamTest method testTerminalOperationDelegatesToAndClosesDelegate.
@Theory
public void testTerminalOperationDelegatesToAndClosesDelegate(@FromDataPoints("terminalOperations") TerminalOperation terminalOperation) {
Object expectedResult = terminalOperation.result();
if (expectedResult != null) {
when(terminalOperation.apply(delegate)).thenReturn(expectedResult);
}
Object result = terminalOperation.apply(inTest);
InOrder inOrder = inOrder(delegate);
assertThat(result, is(expectedResult));
inOrder.verify(delegate).close();
}
use of org.junit.experimental.theories.Theory in project cryptomator by cryptomator.
the class AutoClosingStreamTest method testIntermediateOperationReturnsNewAutoClosingStream.
@Theory
public void testIntermediateOperationReturnsNewAutoClosingStream(@FromDataPoints("intermediateOperations") IntermediateOperation intermediateOperation) {
BaseStream newDelegate = (BaseStream) mock(intermediateOperation.type());
when(intermediateOperation.apply(delegate)).thenReturn(newDelegate);
BaseStream result = intermediateOperation.apply(inTest);
assertThat(result, isAutoClosing());
verifyDelegate(result, newDelegate);
}
use of org.junit.experimental.theories.Theory in project cryptomator by cryptomator.
the class AutoClosingStreamTest method testTerminalOperationDelegatesToAndClosesDelegate.
@Theory
public void testTerminalOperationDelegatesToAndClosesDelegate(@FromDataPoints("terminalOperations") TerminalOperation terminalOperation) {
Object expectedResult = terminalOperation.result();
if (expectedResult != null) {
when(terminalOperation.apply(delegate)).thenReturn(expectedResult);
}
Object result = terminalOperation.apply(inTest);
InOrder inOrder = inOrder(delegate);
assertThat(result, is(expectedResult));
inOrder.verify(delegate).close();
}
use of org.junit.experimental.theories.Theory in project HdrHistogram by HdrHistogram.
the class HistogramEncodingTest method testHistogramEncoding.
@Theory
public void testHistogramEncoding(BufferAllocator allocator) throws Exception {
ShortCountsHistogram shortCountsHistogram = new ShortCountsHistogram(highestTrackableValue, 3);
IntCountsHistogram intCountsHistogram = new IntCountsHistogram(highestTrackableValue, 3);
Histogram histogram = new Histogram(highestTrackableValue, 3);
AtomicHistogram atomicHistogram = new AtomicHistogram(highestTrackableValue, 3);
ConcurrentHistogram concurrentHistogram = new ConcurrentHistogram(highestTrackableValue, 3);
SynchronizedHistogram synchronizedHistogram = new SynchronizedHistogram(highestTrackableValue, 3);
DoubleHistogram doubleHistogram = new DoubleHistogram(highestTrackableValue * 1000, 3);
for (int i = 0; i < 10000; i++) {
shortCountsHistogram.recordValue(1000 * i);
intCountsHistogram.recordValue(2000 * i);
histogram.recordValue(3000 * i);
atomicHistogram.recordValue(4000 * i);
concurrentHistogram.recordValue(4000 * i);
synchronizedHistogram.recordValue(5000 * i);
doubleHistogram.recordValue(5000 * i);
// Makes some internal shifts happen.
doubleHistogram.recordValue(0.001);
}
System.out.println("Testing encoding of a ShortHistogram:");
ByteBuffer targetBuffer = allocator.allocate(shortCountsHistogram.getNeededByteBufferCapacity());
shortCountsHistogram.encodeIntoByteBuffer(targetBuffer);
targetBuffer.rewind();
ShortCountsHistogram shortCountsHistogram2 = ShortCountsHistogram.decodeFromByteBuffer(targetBuffer, 0);
Assert.assertEquals(shortCountsHistogram, shortCountsHistogram2);
ByteBuffer targetCompressedBuffer = allocator.allocate(shortCountsHistogram.getNeededByteBufferCapacity());
shortCountsHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
targetCompressedBuffer.rewind();
ShortCountsHistogram shortCountsHistogram3 = ShortCountsHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
Assert.assertEquals(shortCountsHistogram, shortCountsHistogram3);
System.out.println("Testing encoding of a IntHistogram:");
targetBuffer = allocator.allocate(intCountsHistogram.getNeededByteBufferCapacity());
intCountsHistogram.encodeIntoByteBuffer(targetBuffer);
targetBuffer.rewind();
IntCountsHistogram intCountsHistogram2 = IntCountsHistogram.decodeFromByteBuffer(targetBuffer, 0);
Assert.assertEquals(intCountsHistogram, intCountsHistogram2);
targetCompressedBuffer = allocator.allocate(intCountsHistogram.getNeededByteBufferCapacity());
intCountsHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
targetCompressedBuffer.rewind();
IntCountsHistogram intCountsHistogram3 = IntCountsHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
Assert.assertEquals(intCountsHistogram, intCountsHistogram3);
System.out.println("Testing encoding of a Histogram:");
targetBuffer = allocator.allocate(histogram.getNeededByteBufferCapacity());
histogram.encodeIntoByteBuffer(targetBuffer);
targetBuffer.rewind();
Histogram histogram2 = Histogram.decodeFromByteBuffer(targetBuffer, 0);
Assert.assertEquals(histogram, histogram2);
targetCompressedBuffer = allocator.allocate(histogram.getNeededByteBufferCapacity());
histogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
targetCompressedBuffer.rewind();
Histogram histogram3 = Histogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
Assert.assertEquals(histogram, histogram3);
System.out.println("Testing encoding of a AtomicHistogram:");
targetBuffer = allocator.allocate(atomicHistogram.getNeededByteBufferCapacity());
atomicHistogram.encodeIntoByteBuffer(targetBuffer);
targetBuffer.rewind();
AtomicHistogram atomicHistogram2 = AtomicHistogram.decodeFromByteBuffer(targetBuffer, 0);
Assert.assertEquals(atomicHistogram, atomicHistogram2);
targetCompressedBuffer = allocator.allocate(atomicHistogram.getNeededByteBufferCapacity());
atomicHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
targetCompressedBuffer.rewind();
AtomicHistogram atomicHistogram3 = AtomicHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
Assert.assertEquals(atomicHistogram, atomicHistogram3);
System.out.println("Testing encoding of a ConcurrentHistogram:");
targetBuffer = allocator.allocate(concurrentHistogram.getNeededByteBufferCapacity());
concurrentHistogram.encodeIntoByteBuffer(targetBuffer);
targetBuffer.rewind();
ConcurrentHistogram concurrentHistogram2 = ConcurrentHistogram.decodeFromByteBuffer(targetBuffer, 0);
Assert.assertEquals(concurrentHistogram, concurrentHistogram2);
targetCompressedBuffer = allocator.allocate(concurrentHistogram.getNeededByteBufferCapacity());
concurrentHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
targetCompressedBuffer.rewind();
ConcurrentHistogram concurrentHistogram3 = ConcurrentHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
Assert.assertEquals(concurrentHistogram, concurrentHistogram3);
System.out.println("Testing encoding of a SynchronizedHistogram:");
targetBuffer = allocator.allocate(synchronizedHistogram.getNeededByteBufferCapacity());
synchronizedHistogram.encodeIntoByteBuffer(targetBuffer);
targetBuffer.rewind();
SynchronizedHistogram synchronizedHistogram2 = SynchronizedHistogram.decodeFromByteBuffer(targetBuffer, 0);
Assert.assertEquals(synchronizedHistogram, synchronizedHistogram2);
synchronizedHistogram.setIntegerToDoubleValueConversionRatio(5.0);
targetCompressedBuffer = allocator.allocate(synchronizedHistogram.getNeededByteBufferCapacity());
synchronizedHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
targetCompressedBuffer.rewind();
SynchronizedHistogram synchronizedHistogram3 = SynchronizedHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
Assert.assertEquals(synchronizedHistogram, synchronizedHistogram3);
System.out.println("Testing encoding of a DoubleHistogram:");
targetBuffer = allocator.allocate(doubleHistogram.getNeededByteBufferCapacity());
doubleHistogram.encodeIntoByteBuffer(targetBuffer);
targetBuffer.rewind();
DoubleHistogram doubleHistogram2 = DoubleHistogram.decodeFromByteBuffer(targetBuffer, 0);
Assert.assertEquals(doubleHistogram, doubleHistogram2);
targetCompressedBuffer = allocator.allocate(doubleHistogram.getNeededByteBufferCapacity());
doubleHistogram.encodeIntoCompressedByteBuffer(targetCompressedBuffer);
targetCompressedBuffer.rewind();
DoubleHistogram doubleHistogram3 = DoubleHistogram.decodeFromCompressedByteBuffer(targetCompressedBuffer, 0);
Assert.assertEquals(doubleHistogram, doubleHistogram3);
}
use of org.junit.experimental.theories.Theory in project opennms by OpenNMS.
the class DurationTest method testStartAndEndSame.
@Theory
public void testStartAndEndSame(Date time) {
Duration d = new Duration(time, time);
assertThat(d.millis(), is(0L));
}
Aggregations