List of usage examples for org.apache.commons.lang3.mutable MutableBoolean MutableBoolean
public MutableBoolean(final Boolean value)
From source file:org.onosproject.store.ecmap.MapDbPersistentStore.java
private void putInternal(K key, V value, Timestamp timestamp) { byte[] keyBytes = serializer.encode(key); byte[] removedBytes = tombstones.get(keyBytes); Timestamp removed = removedBytes == null ? null : serializer.decode(removedBytes); if (removed != null && removed.isNewerThan(timestamp)) { return;/*w w w .j a va 2s . co m*/ } final MutableBoolean updated = new MutableBoolean(false); items.compute(keyBytes, (k, existingBytes) -> { Timestamped<V> existing = existingBytes == null ? null : serializer.decode(existingBytes); if (existing != null && existing.isNewerThan(timestamp)) { updated.setFalse(); return existingBytes; } else { updated.setTrue(); return serializer.encode(new Timestamped<>(value, timestamp)); } }); boolean success = updated.booleanValue(); if (success && removed != null) { tombstones.remove(keyBytes, removedBytes); } database.commit(); }
From source file:org.onosproject.store.ecmap.MapDbPersistentStore.java
private void removeInternal(K key, Timestamp timestamp) { byte[] keyBytes = serializer.encode(key); final MutableBoolean updated = new MutableBoolean(false); items.compute(keyBytes, (k, existingBytes) -> { Timestamp existing = existingBytes == null ? null : serializer.decode(existingBytes); if (existing != null && existing.isNewerThan(timestamp)) { updated.setFalse();/*from www .j a v a2s . c om*/ return existingBytes; } else { updated.setTrue(); // remove from items map return null; } }); if (!updated.booleanValue()) { return; } byte[] timestampBytes = serializer.encode(timestamp); byte[] removedBytes = tombstones.get(keyBytes); Timestamp removedTimestamp = removedBytes == null ? null : serializer.decode(removedBytes); if (removedTimestamp == null) { tombstones.putIfAbsent(keyBytes, timestampBytes); } else if (timestamp.isNewerThan(removedTimestamp)) { tombstones.replace(keyBytes, removedBytes, timestampBytes); } database.commit(); }
From source file:org.pircbotx.ConfigurationTest.java
@Test(dataProvider = "fieldNamesDataProvider", dependsOnMethods = "containSameFieldsTest", description = "Make sure every getter in builder gets called when creating Configuration") @SuppressWarnings("unchecked") public void copyConstructorTest(Class containerClass, Class copiedClass, Object copiedOpject, String getterName) throws Exception { //Get the method that is going to be called final Method methodToCall = copiedClass.getDeclaredMethod(getterName); //Trip if method gets called final MutableBoolean isMethodCalled = new MutableBoolean(false); Object copiedObjectSpied = mock(copiedClass, withSettings().spiedInstance(copiedOpject).defaultAnswer(new Answer() { public Object answer(InvocationOnMock invocation) throws Throwable { if (invocation.getMethod().equals(methodToCall)) isMethodCalled.setValue(true); return invocation.callRealMethod(); }/*w ww . j a va 2 s . co m*/ })); //Call and test containerClass.getDeclaredConstructor(copiedClass).newInstance(copiedObjectSpied); assertTrue(isMethodCalled.getValue(), "Getter " + getterName + " on Builder not called in constructor in class " + containerClass.getCanonicalName()); }
From source file:org.pircbotx.hooks.ListenerAdapterTest.java
@Test(description = "Do an actual test with a sample ListenerAdapter") public void usabilityTest() throws Exception { final MutableBoolean onMessageCalled = new MutableBoolean(false); final MutableBoolean onGenericMessageCalled = new MutableBoolean(false); ListenerAdapter testListener = new ListenerAdapter() { @Override/*from w w w .j a v a 2 s. com*/ public void onMessage(MessageEvent event) throws Exception { onMessageCalled.setValue(true); } @Override public void onGenericMessage(GenericMessageEvent event) throws Exception { onGenericMessageCalled.setValue(true); } }; testListener.onEvent(mock(MessageEvent.class)); assertTrue(onMessageCalled.isTrue(), "onMessage wasn't called on MessageEvent"); assertTrue(onGenericMessageCalled.isTrue(), "onGenericMessage wasn't called on MessageEvent"); }
From source file:org.sejda.cli.CommandLineTestBuilder.java
public void assertTaskCompletes(String commandLine) { final MutableBoolean taskCompleted = new MutableBoolean(false); GlobalNotificationContext.getContext().addListener(new EventListener<TaskExecutionCompletedEvent>() { @Override/* ww w . j a v a2 s . c o m*/ public void onEvent(TaskExecutionCompletedEvent event) { taskCompleted.setValue(true); } }); String consoleOutput = invokeConsoleAndReturnSystemOut(commandLine); assertThat("Task did not complete. Console output was:\n" + consoleOutput, taskCompleted.toBoolean(), is(true)); }
From source file:org.vaadin.viritin.FilterableListContainerTest.java
@Test public void clearFilters() { final List<Person> listOfPersons = getListOfPersons(100); FilterableListContainer<Person> container = new FilterableListContainer<>(listOfPersons); container.addContainerFilter(new SimpleStringFilter("firstName", "First1", true, true)); Assert.assertNotSame(listOfPersons.size(), container.size()); container.removeAllContainerFilters(); Assert.assertEquals(listOfPersons.size(), container.size()); container.addContainerFilter(new SimpleStringFilter("firstName", "foobar", true, true)); Assert.assertEquals(0, container.size()); final MutableBoolean fired = new MutableBoolean(false); container.addListener(new Container.ItemSetChangeListener() { @Override//from w w w .ja v a 2 s . co m public void containerItemSetChange(Container.ItemSetChangeEvent event) { fired.setTrue(); } }); container.removeAllContainerFilters(); Assert.assertTrue(fired.booleanValue()); Assert.assertEquals(listOfPersons.size(), container.size()); }
From source file:org.xwiki.notifications.preferences.script.NotificationPreferenceScriptServiceTest.java
@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 -> {/*ww w . j a v a 2 s .c o m*/ 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()); }