499500501502503504505506507508509
BufferedValueModel buffer = new BufferedValueModel(wrapped, trigger1); buffer.setValue("change1"); Object wrappedValue = wrapped.getValue(); Object bufferedValue = buffer.getValue(); trigger2.commit(); assertEquals( "Changing the unrelated trigger2 to commit has no effect on the wrapped.", wrapped.getValue(), wrappedValue); assertSame(
547548549550551552553554555556557
"Changing the unrelated trigger1 to revert has no effect on the buffer.", buffer.getValue(), bufferedValue); // Commit using trigger2. trigger2.commit(); assertEquals( "Changing the current trigger2 to commit commits the buffered value.", buffer.getValue(), wrapped.getValue());
2728293031323334353637
*/ public class CommitTriggerTests extends TestCase { public void testCommitTrigger() { CommitTrigger ct = new CommitTrigger(); ct.commit(); ct.revert(); TestCommitTriggerListener l = new TestCommitTriggerListener(); ct.addCommitTriggerListener(l); assertEquals(0, l.commits);
3536373839404142434445
TestCommitTriggerListener l = new TestCommitTriggerListener(); ct.addCommitTriggerListener(l); assertEquals(0, l.commits); assertEquals(0, l.reverts); ct.commit(); assertEquals(1, l.commits); ct.commit(); assertEquals(2, l.commits); assertEquals(0, l.reverts); ct.revert();
3738394041424344454647
assertEquals(0, l.commits); assertEquals(0, l.reverts); ct.commit(); assertEquals(1, l.commits); ct.commit(); assertEquals(2, l.commits); assertEquals(0, l.reverts); ct.revert(); assertEquals(2, l.commits); assertEquals(1, l.reverts);
4647484950515253545556
assertEquals(2, l.commits); assertEquals(1, l.reverts); ct.removeCommitTriggerListener(l); ct.commit(); assertEquals(2, l.commits); ct.revert(); assertEquals(1, l.reverts); }