Skip to content

Instantly share code, notes, and snippets.

@Test public void
print_transactions_in_reverse_chronological_order() {
given(clock.timeAsString()).willReturn("01/04/2014", "02/04/2014", "10/04/2014");
account.deposit(1000);
account.withdraw(100);
account.deposit(500);
account.printStatement();
@sandromancuso
sandromancuso / gist:4240549
Created December 8, 2012 14:50
Object Calisthenics Rules
The Rules
1. One level of indentation per method
2. Don’t use the ELSE keyword
3. Wrap all primitives and Strings
4. First class collections
5. One dot per line
6. Don’t abbreviate
7. Keep all entities small (50 lines)
8. No classes with more than two instance variables
@sandromancuso
sandromancuso / gist:4162841
Created November 28, 2012 17:49
ATM BDD spec
Story: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed
Scenario 1: Account has sufficient funds
Given the account balance is $100
And the card is valid
And the machine contains enough money
@sandromancuso
sandromancuso / gist:4162826
Created November 28, 2012 17:47
Roman numeral convertion BDD spec
Feature: Convert decimal numbers to roman numerals
Scenario Outline: Generate a roman numeral
Given a decimal number equal to <decimal_number>
When the roman numeral is generated
Then roman numeral should be <roman_numeral>
Examples:
| decimal_number | roman_numeral |
public class Item {
private String name;
private int sellIn;
private int quality;
public Item(String name, int sellIn, int quality) {
this.setName(name);
this.setSellIn(sellIn);
this.setQuality(quality);
}
@sandromancuso
sandromancuso / GildedRoseTest.java
Created November 11, 2012 23:17
GildedRose test class using ApprovalTests for Golden Master test
package org.craftedsw.gildedrose;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.approvaltests.Approvals;
import org.junit.Before;
import org.junit.Test;
package org.craftedsw.testingbuilders;
public class TradeBuilder {
private String inboundMessage;
private ReportabilityDecision reportabilityDecision;
public static TradeBuilder aTrade() {
return new TradeBuilder();
}
package org.craftedsw.testingbuilders;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
package org.craftedsw.testingbuilders;
import static org.craftedsw.testingbuilders.TradeBuilder.aTrade;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
package org.craftedsw.testingbuilders;
public class Trade {
private String inboundMessage;
private ReportabilityDecision reportabilityDecision;
public String getInboundMessage() {
return this.inboundMessage;
}