// Testing the drive method by mocking the location class three times, stubbing the getCon1 and // getCon2 methods of the first location to return the second and third locations. // Calling drive() with the first location and 0 as arguments should return the second location // and with the first location and 1 as arguments drive should return the third location. @Test public void testDrive() { City myCity = new City(); Location mockLoc1 = Mockito.mock(Location.class); Location mockLoc2 = Mockito.mock(Location.class); Location mockLoc3 = Mockito.mock(Location.class); Mockito.when(mockLoc1.getCon1()).thenReturn(mockLoc2); Mockito.when(mockLoc1.getCon2()).thenReturn(mockLoc3); assertEquals(mockLoc2, myCity.drive(mockLoc1, 0)); assertEquals(mockLoc3, myCity.drive(mockLoc1, 1)); }