Skip to content

Instantly share code, notes, and snippets.

@domix
Created December 7, 2009 22:31
Show Gist options
  • Save domix/251192 to your computer and use it in GitHub Desktop.
Save domix/251192 to your computer and use it in GitHub Desktop.
package testing;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@RunWith(MockInyectRunner.class)
public class UnderTestTest {
@UnderTest
private UnderTestObject longi;
@Mock
private Colaborator colaboradorEnTest;
@Mock
private Colaborator1 colaborador1EnTest;
@Before
public void foo() {
System.out.println("En el before");
}
@Test
public void testname() throws Exception {
when(colaboradorEnTest.foo()).thenReturn(true);
when(colaborador1EnTest.foo()).thenReturn(false);
assertNotNull(longi);
assertTrue(longi.foo());
assertFalse(longi.bar());
}
}
class UnderTestObject {
private Colaborator colaborador;
private Colaborator1 colaborador1;
public boolean foo() {
return colaborador.foo();
}
public boolean bar() {
return colaborador1.foo();
}
}
class Colaborator {
public boolean foo() {
return false;
}
}
class Colaborator1 {
public boolean foo() {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment