At a client, we were testing a simple feature, but the resulting tests had much subtle repetition:
(source code is here)
@Test public void log_when_sending_greeting_letters() { sut.send(mock(GreetingLetter.class)); verify(logger).sentGreetingLetter(); } @Test public void log_when_sending_love_letters() { sut.send(mock(LoveLetter.class)); verify(logger).sentLoveLetter(); } and the production code:
public class MailSender { private final EventLogger eventLogger; public MailSender (final EventLogger eventLogger) { this.eventLogger = eventLogger; } public void send (final GreetingLetter letter) { // more business logic eventLogger.
I’ve found this set of tweets about the craftsmanship analogy by Sarah Mei:
We’ve read the fourth chapter from the Practical Object-Oriented Design in Ruby, by Sandi Metz.
These are the concepts and links brought up during the discussion:
The craftsmanship analogy, as exposed in these tweets Difference between function and method What vs How (also present in the GOOS)
2016-04 update: I’ve discovered that the original Rakefile does a similar job. See here
After a while, the generation of the static site using Octopress 2 was starting to be slow (around 2 minutes for 85 posts) for the kind of fast feedback cycle I was expecting.
Inspired by their new features in Octopress 3, one of them being faster site generation, I decided to retrofit my installation with the same feature.
A friend and I were arguing about this code (fragment):
public void register (final String userName) { try { registeredUsers.add(new User(userName)); } catch (AlreadyRegisteredUserException e) { resultListener.alreadyRegistered(userName); } } I would have said that resultListener is a dependency as, first, it was injected by the constructor, second, it is necessary for the execution (negative case).
He suggested that:
being injected through the constructor is usually what happens with dependencies, but does not make it one (i.
We categorize an object’s peers (loosely) into three types of relationship. An object might have:
Dependencies: Services that the object requires from its peers so it can perform its responsibilities. The object cannot function without these services. It should not be possible to create the object without them. For example, a graphics package will need something like a screen or canvas to draw on–it doesn’t make sense without one.