stock_test.j
use testing;
func soldOut() { reserve("tea", 5); }
func testSoldOut() {
testing.assertThrows("soldOut", "stock");
testing.assertThrowsArgs("reserve", ["tea", 5], "stock");
}
func testWrongKind() {
testing.assertThrows("soldOut", "rest");
}
func testAvailable() {
def left as int init 0;
try {
reserve("tea", 5);
} catch (e) {
if ($e.kind == "stock") {
def se as StockError init $e;
$left = $se.available;
}
}
testing.assertEqual($left, 3);
}