Last change
on this file since 916 was
898,
checked in by gav, 14 years ago
|
Add savePurchaseOrderNumber() and savePurchaseOrderNumberRange() to PurchaseOrderService.
|
File size:
1.1 KB
|
Line | |
---|
1 | package com.henyo |
---|
2 | |
---|
3 | import grails.test.GrailsUnitTestCase |
---|
4 | import org.springframework.transaction.TransactionStatus |
---|
5 | |
---|
6 | /** |
---|
7 | * Base unit test class with mock extensions. |
---|
8 | * http://blog.henyo.com/2009/04/mocking-transactions-for-unit-testing.html |
---|
9 | */ |
---|
10 | class BaseUnitTestCase extends GrailsUnitTestCase { |
---|
11 | |
---|
12 | def statusControls |
---|
13 | |
---|
14 | protected void setUp() { |
---|
15 | super.setUp() |
---|
16 | statusControls = [] |
---|
17 | } |
---|
18 | |
---|
19 | protected void tearDown(){ |
---|
20 | statusControls.each{ |
---|
21 | it.verify() |
---|
22 | } |
---|
23 | statusControls.clear() |
---|
24 | super.tearDown() |
---|
25 | } |
---|
26 | |
---|
27 | def mockForTransaction(Class clazz,boolean expectRollback = false){ |
---|
28 | registerMetaClass(clazz) |
---|
29 | def statusControl = mockFor(TransactionStatus) |
---|
30 | statusControls << statusControl |
---|
31 | if(expectRollback) |
---|
32 | statusControl.demand.setRollbackOnly(1..1) { println 'setRollbackOnly called'} |
---|
33 | def status = statusControl.createMock() |
---|
34 | clazz.metaClass.'static'.withTransaction = { |
---|
35 | Closure callable -> callable.call(status) |
---|
36 | } |
---|
37 | return statusControl |
---|
38 | } |
---|
39 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.