File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
src/test/java/co/stateful Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 3030package co .stateful ;
3131
3232import co .stateful .mock .MkSttc ;
33+ import java .io .IOException ;
3334import java .util .concurrent .Callable ;
3435import org .hamcrest .MatcherAssert ;
3536import org .hamcrest .Matchers ;
3637import org .junit .Test ;
38+ import org .mockito .Mockito ;
3739
3840/**
3941 * Test case for {@link Atomic}.
@@ -63,4 +65,30 @@ public String call() throws Exception {
6365 );
6466 }
6567
68+ /**
69+ * Atomic can unlock if crashed.
70+ * @throws Exception If some problem inside
71+ */
72+ @ Test
73+ public void unlocksWhenCrashed () throws Exception {
74+ final Lock lock = Mockito .mock (Lock .class );
75+ Mockito .doReturn (true ).when (lock ).lock ();
76+ try {
77+ new Atomic <String >(
78+ new Callable <String >() {
79+ @ Override
80+ public String call () throws Exception {
81+ throw new IOException ("expected one" );
82+ }
83+ },
84+ lock
85+ ).call ();
86+ } catch (final IOException ex ) {
87+ MatcherAssert .assertThat (
88+ ex .getLocalizedMessage (), Matchers .startsWith ("expected" )
89+ );
90+ }
91+ Mockito .verify (lock ).unlock ();
92+ }
93+
6694}
You can’t perform that action at this time.
0 commit comments