29
29
import junit .framework .TestCase ;
30
30
import org .hibernate .HibernateException ;
31
31
32
- /** @author Dhanji R. Prasanna ([email protected] ) */
32
+ /**
33
+ * @author Dhanji R. Prasanna ([email protected] )
34
+ */
33
35
34
36
public class JpaWorkManagerTest extends TestCase {
35
37
private Injector injector ;
@@ -41,9 +43,6 @@ public class JpaWorkManagerTest extends TestCase {
41
43
@ Override
42
44
public void setUp () {
43
45
injector = Guice .createInjector (new JpaPersistModule ("testUnit" ));
44
-
45
- //startup persistence
46
- injector .getInstance (PersistService .class ).start ();
47
46
}
48
47
49
48
@ Override
@@ -56,6 +55,7 @@ public void tearDown() {
56
55
}
57
56
58
57
public void testWorkManagerInSession () {
58
+ injector .getInstance (PersistService .class ).start ();
59
59
injector .getInstance (UnitOfWork .class ).begin ();
60
60
try {
61
61
injector .getInstance (TransactionalObject .class ).runOperationInTxn ();
@@ -89,15 +89,24 @@ public void testWorkManagerInSession() {
89
89
}
90
90
}
91
91
92
+ public void testStartMoreThanOnce () {
93
+ injector .getInstance (PersistService .class ).start ();
94
+ // No exception is thrown on subsequent start.
95
+ injector .getInstance (PersistService .class ).start ();
96
+ }
97
+
92
98
public void testCloseMoreThanOnce () {
99
+ injector .getInstance (PersistService .class ).start ();
100
+ injector .getInstance (PersistService .class ).stop ();
101
+ // No exception is thrown on subsequent stop.
93
102
injector .getInstance (PersistService .class ).stop ();
103
+ }
94
104
95
- try {
96
- injector .getInstance (PersistService .class ).stop ();
97
- fail ();
98
- } catch (IllegalStateException e ) {
99
- // Ignored.
100
- }
105
+ public void testCloseWithoutStart () {
106
+ // No exception.
107
+ injector .getInstance (PersistService .class ).stop ();
108
+ // (but also start it so we can have one tearDown that unconditionally stops started things)
109
+ injector .getInstance (PersistService .class ).start ();
101
110
}
102
111
103
112
public static class TransactionalObject {
0 commit comments