@Test public void testShouldCompareName() { Plane plane = new Plane("A380"); assertTrue(plane.sameAs("A380")); assertFalse(plane.sameAs("B747")); } Alt + Enter > Create method ‘sameAs’
testShouldCompareName() { Plane plane = new Plane("A380"); assertTrue(plane.sameAs("A380")); assertFalse(plane.sameAs("B747")); } } ! java.lang.RuntimeException: Method v in android.util.Log not mocked. at android.util.Log.v(Log.java) at com.skocken.junittest.Plane.sameAs(Plane.java:14) at com.skocken.junittest.PlaneTest.testShouldCompareName(PlaneTest.java:13)
} public static boolean equals(CharSequence a, CharSequence b) { … } public static boolean equals(CharSequence a, CharSequence b) { return false; } TextUtils.java Mock of TextUtils.java
final GameBoard.Player PLAYER_AI = GameBoard.Player.J2; private GameBoard mGameBoard; private AI mAI; @Before public void setUp() throws Exception { mGameBoard = new GameBoard(); mAI = new AI(mGameBoard, PLAYER_AI); } }
private final GameBoard mGameBoard = new GameBoard(); private final GameBoard.Player mCurrentPlayer = GameBoard.Player.J1; private final AI mAI = new AI(mGameBoard, GameBoard.Player.J2); @Override public GameBoard getGameBoard() { return mGameBoard; } @Override public void play(int x, int y) { mGameBoard.play(mCurrentPlayer, x, y); mAI.playNext(); getPresenter().refreshBoard(); } }