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(){
		// HINT: pass a safe Collaborator implementation to constructor
		// new ClassUnderTest(new Collaborator(){... it should not be the
		// objective of this test to test that collaborator, so replace it
		new ClassUnderTest().doSomething();
	}
	
}

@@ -358,24 +358,127 @@
 );%0A%09%09%7D%0A%09%7D%0A%09%0A
+%09static class PassingCollaborator implements Collaborator %7B%0A%09%09public void doBusinessStuff() %7B%0A%09%09%7D%0A%09%7D%0A%09%0A
 %09static clas
@@ -657,25 +657,23 @@
 his(new 
-Explosive
+Passing
 Collabor

Complete. 193 of 193.