blob: b0a35bbdc47b33b3488cd0b820b9d2132eea71ba [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Tests</title>
<link rel="stylesheet" type="text/css" href="jsunit/css/jsUnitStyle.css">
<script language="JavaScript" type="text/javascript" src="../../jsunit/app/jsUnitCore.js"></script>
<script language="JavaScript" type="text/javascript" src="../mock4js.js"></script>
<script language="JavaScript" type="text/javascript" src="PriceService.js"></script>
<script language="JavaScript" type="text/javascript">
Mock4JS.addMockSupport(this);
var mockPriceFetcher;
var mockPriceCache;
var priceService;
function setUp() {
Mock4JS.clearMocksToVerify();
mockPriceFetcher = mock(PriceFetcher);
mockPriceCache = mock(PriceCache);
priceService = new PriceService(mockPriceFetcher.proxy(), mockPriceCache.proxy());
}
function tearDown() {
Mock4JS.verifyAllMocks();
}
function testGetsPriceFromFetcherWhenPriceNotInCache() {
mockPriceCache.expects(once()).getCachedPrice("USDGBP").will(returnValue(null));
mockPriceFetcher.expects(once()).getPriceFromServer("USDGBP").will(returnValue(123.4));
mockPriceCache.expects(once()).setCachedPrice("USDGBP", 123.4);
var result = priceService.getPrice("USDGBP");
assertEquals("Should have returned price from server", 123.4, result);
}
function testDoesntGetsPriceFromFetcherWhenPriceAlreadyInCache() {
mockPriceCache.expects(once()).getCachedPrice("USDGBP").will(returnValue(123.4));
mockPriceCache.expects(never()).setCachedPrice();
mockPriceFetcher.expects(never()).getPriceFromServer("USDGBP");
var result = priceService.getPrice("USDGBP");
assertEquals("Should have returned price from cache", 123.4, result);
}
</script>
</head>
<body>
<h1>JsUnit Tests</h1>
<p>This page contains some JsUnit tests. To see them, take a look at the source.</p>
</body>
</html>