Skip to content

Instantly share code, notes, and snippets.

@javaeeeee
javaeeeee / Bootstrap 3 Column Offsetting
Created November 1, 2014 06:03
Bootstrap 3 Column Offsetting
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="row">
<div class="col-md-3"><i class="glyphicon glyphicon-cloud green"></i></div>
<div class="col-md-3"><i class="glyphicon glyphicon-envelope green"></i></div>
<div class="col-md-3"><i class="glyphicon glyphicon-search green"></i></div>
<div class="col-md-3"><i class="glyphicon glyphicon-film green"></i></div>
</div> <!-- /.row -->
</div>
@javaeeeee
javaeeeee / Bootstrap 3 Basic Grid Structure
Created November 1, 2014 06:11
Bootstrap 3 Basic Grid Structure
<div class="container">
<div class="row">
<div class="col-*-*"></div>
<div class="col-*-*"></div>
<!-- You can place as many col-*-* as your like. If there is more
than 12 columns, they will be wrapped for you onto a new line -->
<div class="col-*-*"></div>
</div> <!-- /.row -->
<!-- You can place as many col-*-* as your like. -->
</div> <!-- /.container-->
@javaeeeee
javaeeeee / Bootstrap 3 Basic Form Template
Created November 1, 2014 15:08
Bootstrap 3 Basic Form Template
<div class="container">
<form class="form-horizontal" role="form">
<div class="form-group">
<!-- Place here whatever form control you need -->
</div> <!-- /.form-group -->
<!-- Place as much form groups as you need -->
<div class="form-group">
<!-- Place here whatever form control you need -->
</div> <!-- /.form-group -->
</form> <!-- /form -->
@javaeeeee
javaeeeee / Registration Form
Created November 25, 2014 04:44
Registration Form Example
<div class="container">
<form class="form-horizontal" role="form">
<h2>Registration Form</h2>
<div class="form-group">
<label for="firstName" class="col-sm-3 control-label">Full Name</label>
<div class="col-sm-9">
<input type="text" id="firstName" placeholder="Full Name" class="form-control" autofocus>
<span class="help-block">Last Name, First Name, eg.: Smith, Harry</span>
</div>
</div>
@javaeeeee
javaeeeee / nodoubles
Created January 10, 2015 13:13
A simple method which doesn't need Test Doubles to be tested
boolean isTransactionPossible(final BigDecimal amount,
final BigDecimal balance) {
return balance.compareTo(amount) >= 0;
}
@javaeeeee
javaeeeee / ATM withdraw
Created January 10, 2015 13:16
Withdraw method of an ATM
public void withdrawCash() throws BankServiceException {
//Show user options to withdraw cash
screen.displayMenuOfWithdrowalAmounts();
//Read amount from the keypad
BigDecimal amount = keypad.getAmount();
//Connect to the bank and check balance
BigDecimal balance = bankService.getBalance();
@javaeeeee
javaeeeee / test withdraw
Created January 10, 2015 13:18
A test of a withdraw method of an ATM using Mockito and test doubles
@RunWith(MockitoJUnitRunner.class)
public class ATMTest {
private ATM sut;
@Mock
private BankService bankService;
@Mock
private CashDispenser cashDispenser;
@Mock
private DepositSlot depositSlot;
@javaeeeee
javaeeeee / throw exception
Created January 10, 2015 13:19
A method used to show how to test exceptional situation using Mockito
public void showBalance() {
try {
BigDecimal balance = bankService.getBalance();
screen.displayBalance(balance);
} catch (BankServiceException e) {
screen.displayError(BANK_SERVICE_ERROR);
}
}
@javaeeeee
javaeeeee / stub exception
Created January 10, 2015 13:21
A Mockito test simulating exception
@Test
public void testShowBalance() throws BankServiceException {
//given
Mockito.when(bankService.getBalance())
.thenThrow(new BankServiceException());
//when
sut.showBalance();
//then
@javaeeeee
javaeeeee / zero interactions
Created January 10, 2015 13:22
A mockito test to make sure only desired interactions took place
@Test
public void testWithdrawCashNotEnoughMoneyOnAccount() throws BankServiceException {
//given
BigDecimal amount = new BigDecimal("1000");
BigDecimal balance = new BigDecimal("500");
Mockito.when(keypad.getAmount()).thenReturn(amount);
Mockito.when(bankService.getBalance()).thenReturn(balance);
Mockito.when(cashDispenser.isThereEnoughMoney(amount)).thenReturn(true);
//when