Skip to content

Instantly share code, notes, and snippets.

curl -v -H "Accept: text/plain" http://localhost:6666/time
HTTP/1.1 200 OK
Content-Type: text/plain
Content-Length: 21
Server: Jetty(9.0.5.v20130815)
It's currently 20:59
@Test
public void saysTheCurrentTime() {
givenTheCurrentTimeIs("20:15");
whenAUserChecksTheTime();
thenTheUserSees("It's currently 20:15!");
}
public class FixedClock implements Clock {
private Date fixedNow;
@Override
public Date now() {
return fixedNow;
}
public void setNow(Date fixedNow) {
this.fixedNow = fixedNow;
@Before
public void startApplication() {
clock = new FixedClock();
timeExpert = new TimeExpertServer(clock);
timeExpert.start();
}
@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);
@Path("time")
public class TimeResource {
private final Clock clock;
public TimeResource(Clock clock) {
this.clock = clock;
}
@GET
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) {
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();
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
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