Skip to content

Instantly share code, notes, and snippets.

@Synesso
Created August 25, 2008 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Synesso/7061 to your computer and use it in GitHub Desktop.
Save Synesso/7061 to your computer and use it in GitHub Desktop.
package au.com.loftinspace;
import com.googlecode.instinct.marker.annotate.Subject;
import com.googlecode.instinct.marker.annotate.Mock;
import com.googlecode.instinct.marker.annotate.Specification;
import com.googlecode.instinct.marker.annotate.BeforeSpecification;
import static com.googlecode.instinct.expect.Expect.expect;
import com.googlecode.instinct.integrate.junit4.InstinctRunner;
import static org.hamcrest.core.IsInstanceOf.instanceOf;
import java.util.List;
import java.util.LinkedList;
import java.util.ArrayList;
import org.jmock.Expectations;
import org.junit.runner.RunWith;
import org.hamcrest.Matcher;
@RunWith(InstinctRunner.class)
public class AListUserAdaptor {
@Subject
ListUserAdaptor listUserAdaptor;
@Mock
ListUser mockListUser;
@BeforeSpecification
public void setUp() {
listUserAdaptor = new ListUserAdaptor();
listUserAdaptor.setListUser(mockListUser);
}
@Specification
public void shouldUseArrayListsOnListUser() {
/*
This should fail and does, because the expected type (ArrayList) does not match the actual type
(LinkedList) at runtime
*/
expect.that(new Expectations() {
{
one(mockListUser).useAList(withAnInstanceOf(ArrayList.class));
}
private <T> T withAnInstanceOf(Class<T> aClass) {
return with((Matcher<T>) instanceOf(aClass));
}
});
listUserAdaptor.useAList();
}
private class ListUserAdaptor {
public ListUserAdaptor() {
}
private ListUser listUser;
public void setListUser(ListUser listUser) {
this.listUser = listUser;
}
public void useAList() {
listUser.useAList(new LinkedList());
}
}
private class ListUser {
public void useAList(List list) {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment