use of org.apache.commons.lang3.mutable.MutableBoolean in project xwiki-platform by xwiki.
the class NotificationPreferenceScriptServiceTest method saveNotificationPreferences.
@Test
public void saveNotificationPreferences() throws Exception {
DocumentReference userRef = new DocumentReference("xwiki", "XWiki", "UserA");
NotificationPreferenceImpl existingPref1 = new NotificationPreferenceImpl(true, NotificationFormat.ALERT, "create");
NotificationPreferenceImpl existingPref2 = new NotificationPreferenceImpl(true, NotificationFormat.EMAIL, "update");
NotificationPreferenceImpl existingPref3 = new NotificationPreferenceImpl(false, NotificationFormat.EMAIL, "delete");
when(notificationPreferenceManager.getAllPreferences(eq(userRef))).thenReturn(Arrays.asList(existingPref1, existingPref2, existingPref3));
final MutableBoolean isOk = new MutableBoolean(false);
doAnswer(invocationOnMock -> {
List<NotificationPreference> prefsToSave = invocationOnMock.getArgument(0);
// 1 of the preferences contained in the JSON file should be saved because the inherited preference
// is the same
assertEquals(9, prefsToSave.size());
assertTrue(prefsToSave.contains(existingPref1));
assertTrue(prefsToSave.contains(existingPref2));
assertFalse(prefsToSave.contains(existingPref3));
isOk.setTrue();
return true;
}).when(notificationPreferenceManager).savePreferences(any(List.class));
mocker.getComponentUnderTest().saveNotificationPreferences(IOUtils.toString(getClass().getResourceAsStream("/preferences.json")), userRef);
assertTrue(isOk.booleanValue());
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.
the class SimpleDoneQueryQueueManagerTest method resetPermitsTest.
@Test
public void resetPermitsTest() throws Exception {
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
sdqqm.enqueue(query, null, new MutableBoolean(false));
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.beginWindow(1);
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
qb = sdqqm.dequeueBlock();
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
testBlocking(sdqqm);
sdqqm.endWindow();
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.
the class SimpleDoneQueryQueueManagerTest method firstDoneTest.
@Test
public void firstDoneTest() {
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
sdqqm.enqueue(query, null, new MutableBoolean(true));
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeue();
Assert.assertEquals("Should return back null.", null, qb);
sdqqm.endWindow();
sdqqm.beginWindow(1);
qb = sdqqm.dequeue();
Assert.assertEquals("Should return back null.", null, qb);
qb = sdqqm.dequeue();
Assert.assertEquals("Should return back null.", null, qb);
sdqqm.endWindow();
sdqqm.teardown();
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project apex-malhar by apache.
the class SimpleDoneQueryQueueManagerTest method expiredTestBlockingExpiredFirstValidLast.
@Test
public void expiredTestBlockingExpiredFirstValidLast() throws Exception {
SimpleDoneQueueManager<Query, Void> sdqqm = new SimpleDoneQueueManager<Query, Void>();
sdqqm.setup(null);
sdqqm.beginWindow(0);
Query query = new MockQuery("1");
MutableBoolean queueContext = new MutableBoolean(false);
sdqqm.enqueue(query, null, queueContext);
Query query1 = new MockQuery("2");
MutableBoolean queueContext1 = new MutableBoolean(false);
sdqqm.enqueue(query1, null, queueContext1);
Assert.assertEquals(2, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
QueryBundle<Query, Void, MutableBoolean> qb = sdqqm.dequeueBlock();
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
sdqqm.endWindow();
sdqqm.beginWindow(1);
Assert.assertEquals(2, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
queueContext.setValue(true);
qb = sdqqm.dequeueBlock();
Assert.assertEquals(0, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
testBlocking(sdqqm);
sdqqm.endWindow();
sdqqm.beginWindow(2);
Assert.assertEquals(1, sdqqm.getNumLeft());
Assert.assertEquals(sdqqm.getNumPermits(), sdqqm.getNumLeft());
qb = sdqqm.dequeueBlock();
testBlocking(sdqqm);
sdqqm.endWindow();
sdqqm.teardown();
}
use of org.apache.commons.lang3.mutable.MutableBoolean in project sling-org-apache-sling-testing-clients by apache.
the class PollingTest method testCallableOnce.
//
// Tests with Callable
//
@Test
public void testCallableOnce() throws Exception {
final MutableInt callCount = new MutableInt(0);
final MutableBoolean called = new MutableBoolean(false);
Polling p = new Polling(() -> {
callCount.increment();
return true;
});
p.poll(500, 10);
assertEquals(1, callCount.intValue());
}
Aggregations