Created
July 21, 2014 20:20
-
-
Save koalahamlet/75631c9c5f252643fcc1 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 advanced; | |
import com.sandwich.koan.Koan; | |
import static com.sandwich.util.Assert.fail; | |
public class AboutMocks { | |
static interface Collaborator { | |
public void doBusinessStuff(); | |
} | |
static class ExplosiveCollaborator implements Collaborator { | |
public void doBusinessStuff() { | |
fail("Default collaborator's behavior is complicating testing."); | |
} | |
} | |
static class ClassUnderTest { | |
Collaborator c; | |
public ClassUnderTest(){ | |
// default is to pass a broken Collaborator, test should pass one | |
// that doesn't throw exception | |
this(new ExplosiveCollaborator()); | |
} | |
public ClassUnderTest(Collaborator c){ | |
this.c = c; | |
} | |
public boolean doSomething(){ | |
c.doBusinessStuff(); | |
return true; | |
} | |
} | |
@Koan | |
public void simpleAnonymousMock(){ | |
new ClassUnderTest().doSomething(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
earlier I had tried
but it still failed