Skip to content

Testing

Philippe Marschall edited this page Oct 13, 2016 · 3 revisions

Stored procedure interfaces can easily used in testing without requiring database access. You can either use stubbing or mocking.

Given an interface

public interface TaxProcedures {

  BigDecimal salesTax(BigDecimal subtotal);

}

Stubbing

You can simply implement the interface for tests.

public class StubTaxProcedures implements TaxProcedures {

  public BigDecimal salesTax(BigDecimal subtotal) {
    return subtotal.multiply(new BigDecimal("0.06"));
  }

}

Mocking

Or you can use a mocking framework like Mockito

TaxProcedures procedures = mock(TaxProcedures.class);
when(any()).thenReturn(new BigDecimal("6.01"));
Clone this wiki locally