use of org.junit.experimental.theories.Theory in project cryptomator by cryptomator.
the class AutoClosingDoubleStreamTest method testIntermediateOperationReturnsNewAutoClosingStream.
@Theory
public void testIntermediateOperationReturnsNewAutoClosingStream(@FromDataPoints("intermediateOperations") DoubleermediateOperation 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 AutoClosingDoubleStreamTest 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 AutoClosingIntStreamTest 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 sling by apache.
the class ContentFileCacheTest method testCache.
@Theory
public void testCache(int cacheSize) {
ContentFileCache underTest = new ContentFileCache(cacheSize);
ContentElement content1 = underTest.get("/fs-test/folder2/content", new File("src/test/resources/fs-test/folder2/content.json"));
assertNotNull(content1);
switch(cacheSize) {
case NO_CACHE:
assertEquals(0, underTest.size());
break;
case SMALL_CACHE:
case HUGE_CACHE:
assertEquals(1, underTest.size());
break;
}
ContentElement content2 = underTest.get("/fs-test/folder1/file1a", new File("src/test/resources/fs-test/folder1/file1a.txt"));
assertNull(content2);
switch(cacheSize) {
case NO_CACHE:
assertEquals(0, underTest.size());
break;
case SMALL_CACHE:
assertEquals(1, underTest.size());
break;
case HUGE_CACHE:
assertEquals(2, underTest.size());
break;
}
underTest.remove("/fs-test/folder1/file1a");
switch(cacheSize) {
case NO_CACHE:
case SMALL_CACHE:
assertEquals(0, underTest.size());
break;
case HUGE_CACHE:
assertEquals(1, underTest.size());
break;
}
underTest.clear();
assertEquals(0, underTest.size());
}
use of org.junit.experimental.theories.Theory in project helios by spotify.
the class DeploymentGroupTest method testStopDeploymentGroup.
// A test that...
// * Verifies that the state in ZK is correct after running stop
// * Verifies that the correct exception is thrown when the DG does not exist or there is a
// race condition
@Theory
public void testStopDeploymentGroup(@TestedOn(ints = { 0, 1 }) final int dgExistsInt, @TestedOn(ints = { 0, 1 }) final int tasksExistInt, @TestedOn(ints = { 0, 1 }) final int tasksExistWhenCommittingInt) throws Exception {
final boolean dgExists = dgExistsInt != 0;
final boolean tasksExist = tasksExistInt != 0;
final boolean tasksExistWhenCommitting = tasksExistWhenCommittingInt != 0;
// To be able to simulate triggering the race condition in stopDeploymentGroup we need to do
// some mocking, relying on that the implementation uses client.exists() to check for the
// presence of tasks.
final ZooKeeperClient client = spy(this.client);
when(client.exists(Paths.statusDeploymentGroupTasks(GROUP_NAME))).thenReturn(tasksExist ? mock(Stat.class) : null);
final ZooKeeperMasterModel masterModel = newMasterModel(client);
if (dgExists) {
final DeploymentGroup dg = DeploymentGroup.newBuilder().setName(GROUP_NAME).build();
masterModel.addDeploymentGroup(dg);
}
if (tasksExistWhenCommitting) {
client.ensurePath(Paths.statusDeploymentGroupTasks());
client.create(Paths.statusDeploymentGroupTasks(GROUP_NAME));
}
if (!dgExists) {
exception.expect(DeploymentGroupDoesNotExistException.class);
} else if (tasksExist != tasksExistWhenCommitting) {
exception.expect(HeliosRuntimeException.class);
}
masterModel.stopDeploymentGroup(GROUP_NAME);
// Verify that the state in ZK is correct:
// * tasks are not present
// * the status is set to FAILED
//
// When checking for the existence of the tasks make sure we use the client that doesn't have
// the exists() method mocked out!
assertNull(this.client.exists(Paths.statusDeploymentGroupTasks(GROUP_NAME)));
final DeploymentGroupStatus status = masterModel.getDeploymentGroupStatus(GROUP_NAME);
assertEquals(FAILED, status.getState());
}
Aggregations