Created
August 25, 2008 11:08
-
-
Save Synesso/7061 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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