We need a new method in order to be able to rewrite our legacy code.
At the very end this method will be the one used by our app.
The static method will dissapear after refactoring our whole app (what should be done carefully)
throw new CollaboratorCallException(
"TripDAO should not be invoked on an unit test.");
}
+
+ // At the end and by means of many code refactoring our app
+ // will end up using the instance method. In the meanwhile we
+ // will not be able to remove the static method but at least
+ // we are offering something that can be tested.
+ // Be careful when refactoring this code because in real life
+ // findTripsByUser for sure will be used in many places but again
+ // in the meanwhile with this code we can write unit tests (we
+ // always need to write a test of our legacy code before refactoring it)
+ public List<Trip> tripsBy(User user) {
+ return TripDAO.findTripsByUser(user);
+ }
}
\ No newline at end of file
--- /dev/null
+package org.craftedsw.tripservicekata.trip;
+
+import org.craftedsw.tripservicekata.exception.CollaboratorCallException;
+import org.craftedsw.tripservicekata.user.User;
+import org.junit.Test;
+
+public class TripDAOShould {
+
+ @Test(expected = CollaboratorCallException.class) public void
+ throw_exception_when_retrieving_user_trips() {
+ new TripDAO().tripsBy(new User());
+ }
+}
+++ /dev/null
-package org.craftedsw.tripservicekata.trip;
-
-public class TripDAOTest {
-
-}
import org.craftedsw.tripservicekata.user.User;\r
import org.junit.Before;\r
import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
\r
+@RunWith(MockitoJUnitRunner.class)\r
public class TripServiceShould {\r
\r
private static final User GUEST = null;\r
private static final User ANOTHER_USER = new User();\r
private static final Trip TO_BRAZIL = new Trip();\r
private static final Trip TO_BERLIN = new Trip();\r
+ \r
+ @Mock TripDAO tripDAO;\r
+ private TripService realTripService;\r
private TripService tripService;\r
\r
@Before\r