use of org.jmock.Expectations in project gradle by gradle.
the class DefaultDomainObjectCollectionTest method callsVetoActionOnceBeforeCollectionIsIntersected.
@Test
public void callsVetoActionOnceBeforeCollectionIsIntersected() {
final Action<Void> action = Cast.uncheckedCast(context.mock(Action.class));
container.add("a");
container.add("b");
container.beforeChange(action);
context.checking(new Expectations() {
{
oneOf(action).execute(null);
}
});
container.retainAll(toList());
}
use of org.jmock.Expectations in project gradle by gradle.
the class DefaultDomainObjectCollectionTest method callsVetoActionBeforeObjectIsAdded.
@Test
public void callsVetoActionBeforeObjectIsAdded() {
final Action action = context.mock(Action.class);
container.beforeChange(action);
context.checking(new Expectations() {
{
oneOf(action).execute(null);
}
});
container.add("a");
}
use of org.jmock.Expectations in project gradle by gradle.
the class DefaultDomainObjectCollectionTest method objectIsNotAddedWhenVetoActionThrowsAnException.
@Test
public void objectIsNotAddedWhenVetoActionThrowsAnException() {
final Action<Void> action = Cast.uncheckedCast(context.mock(Action.class));
final RuntimeException failure = new RuntimeException();
container.beforeChange(action);
context.checking(new Expectations() {
{
oneOf(action).execute(null);
will(throwException(failure));
}
});
try {
container.add("a");
fail();
} catch (RuntimeException e) {
assertThat(e, sameInstance(failure));
}
assertThat(container, not(hasItem((CharSequence) "a")));
}
use of org.jmock.Expectations in project gradle by gradle.
the class DefaultDomainObjectCollectionTest method callsVetoActionBeforeObjectIsRemoved.
@Test
public void callsVetoActionBeforeObjectIsRemoved() {
final Action<Void> action = Cast.uncheckedCast(context.mock(Action.class));
container.beforeChange(action);
context.checking(new Expectations() {
{
oneOf(action).execute(null);
}
});
container.remove("a");
}
use of org.jmock.Expectations in project gradle by gradle.
the class DefaultDomainObjectCollectionTest method callsRemoveActionWhenObjectRemoved.
@Test
public void callsRemoveActionWhenObjectRemoved() {
@SuppressWarnings("unchecked") final Action<CharSequence> action = context.mock(Action.class);
final String original = "a";
context.checking(new Expectations() {
{
oneOf(action).execute(with(sameInstance(original)));
}
});
container.whenObjectRemoved(action);
container.add(original);
assertTrue(container.remove(original));
}
Aggregations