Skip to content

Instantly share code, notes, and snippets.

Avatar

J. B. Rainsberger jbrains

View GitHub Profile
View FindAllUsersRequest.java
class FindAllUsersRequest extends GetRequest {
public FindAllUsersRequest(parameters) {
super(parameters);
}
public URL getRequestUrl() {
return URL.create("http://www.jbrains.ca/users/all");
}
}
View GetRequestFactory.java
class GetRequestFactory {
static GetRequest findAllUsers(parameters) {
return new GetRequest(requestUrl: URL.create("http://www.jbrains.ca/users/all"), parameters);
}
}
View gist:185020
Controller.initialize() {
parachute = Parachute.new(lander)
detachment_system = DetachmentSystem.new(parachute)
accelerometer = Accelerometer.new()
lander = Lander.new(accelerometer, Altimeter.new())
accelerometer.add_observer(detachment_system)
}
Parachute {
needs a lander
View gist:185026
testOpenParachute() {
parachute = Parachute.new(lander = mock(Lander))
lander.expects().decelerate()
parachute.open()
}
View gist:185027
testLanderDecelerates() {
accelerometer = mock(Accelerometer)
lander = Lander.new(accelerometer)
accelerometer.expects().report_acceleration(-50.ms2)
lander.decelerate()
}
View gist:185029
testAccelerometerCanReportRapidAcceleration() {
accelerometer = Accelerometer.new()
accelerometer.add_observer(observer = mock(AccelerationObserver))
observer.expects().handle_acceleration_report(-50.ms2)
accelerometer.report_acceleration(-50.ms2)
}
View gist:185030
AccelerationObserverTest {
testAccelerationObserverCanHandleRapidAcceleration() {
observer = create_acceleration_observer() // subclass responsibility
this_block {
observer.handle_acceleration_report(-50.ms2)
}.should execute_without_incident
}
}
View gist:185031
DetachmentSystemTest extends AccelerationObserverTest {
// I inherit testAccelerationObserverCanHandleRapidAcceleration()
create_acceleration_observer() {
DetachmentSystem.new(parachute = mock(Parachute))
parachute.expects().detach()
}
}
View gist:185032
DetachmentSystemTest {
testRespondsToRapidAcceleration() {
detachment_system = DetachmentSystem.new(parachute = mock(Parachute))
parachute.expects().detach()
this_block {
detachment_system.handle_acceleration_report(-50.ms2)
}.should execute_without_incident
}
}
View gist:185033
ParachuteTest {
testDetachingWhileLanded() {
parachute = Parachute.new(lander = mock(Lander))
lander.stubs().has_landed().to_return(true)
this_block {
parachute.detach()
}.should execute_without_incident
}
testDetachingWhileNotLanded() {