Skip to content

Instantly share code, notes, and snippets.

@Synesso
Created August 25, 2008 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Synesso/7060 to your computer and use it in GitHub Desktop.
Save Synesso/7060 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 java.util.List;
import java.util.LinkedList;
import java.util.ArrayList;
import org.jmock.Expectations;
import org.junit.runner.RunWith;
@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() {
/*
It might be expected that this would fail, but it does not. Type checking on the List happens at
compile time. The runtime type of the list is not checked as aNonNull resolves to ANYTHING
*/
expect.that(new Expectations() {{
one(mockListUser).useAList(with(aNonNull(ArrayList.class)));
}});
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