Skip to content

Instantly share code, notes, and snippets.

Here's what I meant when I said tests can break even if you only move a method to a different class.
This was the code before we started refactoring:
class BreadShop { ...
public void deposit(int accountId, int creditAmount) {
Account account = accountRepository.getAccount(accountId);
if (account != null) {
final int newBalance = account.deposit(creditAmount);
events.newAccountBalance(accountId, newBalance);
PODCASTS:
http://rubyrogues.com/ - about programming in general, not always Ruby-specific (below a list of some episodes I found good, among many others)
- http://rubyrogues.com/131-rr-how-to-learn/ - episode about learning
- http://rubyrogues.com/023-rr-book-club-smalltalk-best-practice-patterns-with-kent-beck/ - episode with Kent Beck
- http://rubyrogues.com/068-rr-book-club-growing-object-oriented-software-guided-by-tests/ - episode about the GOOS book
http://pragprog.com/podcasts - about programming in general
- includes interviews with UncleBob, Kent Beck, Ward Cunningham, etc...
http://www.functionalgeekery.com/ - about functional programming
module Roots
def self.rootn(x,n)
Math.exp(Math.log(x)/n)
end
end
module Notes
def self.c accidental, octave
Note.new(4, octave, accidental)
end
require_relative 'music'
describe "music kata" do
it "models octaves" do
Notes.c(:simple, 1).pitch.should == 4
Notes.c(:simple, 2).pitch.should == 16
Notes.c(:simple, 8).pitch.should == 88
Notes.e(:simple, 1).pitch.should == 8
end
public class Main {
public static void main(String[] args) {
new Main().startTimeExpert();
}
private void startTimeExpert() {
final TimeExpertServer timeExpert = new TimeExpertServer(new RealClock());
try {
timeExpert.start();
public void start() {
server = new Server(6666);
ServletContextHandler handler = new ServletContextHandler();
handler.setContextPath("");
// adds Jersey Servlet with a customized ResourceConfig
handler.addServlet(new ServletHolder(new ServletContainer(resourceConfig())), "/*");
server.setHandler(handler);
try {
server.start();
} catch (Exception e) {
@Path("time")
public class TimeResource {
private final Clock clock;
public TimeResource(Clock clock) {
this.clock = clock;
}
@GET
@Test
public void saysTheCurrentTime() throws Exception {
givenTheCurrentTimeIs("20:15");
whenAUserChecksTheTime();
thenTheUserSees("It's currently 20:15!");
}
private void givenTheCurrentTimeIs(String currentTime) throws ParseException {
Date currentTimeAsDate = new SimpleDateFormat("HH:mm").parse(currentTime);
clock.setNow(currentTimeAsDate);
@Before
public void startApplication() {
clock = new FixedClock();
timeExpert = new TimeExpertServer(clock);
timeExpert.start();
}
public class FixedClock implements Clock {
private Date fixedNow;
@Override
public Date now() {
return fixedNow;
}
public void setNow(Date fixedNow) {
this.fixedNow = fixedNow;