Skip to content

Commit a74a038

Browse files
author
Yegor Bugayenko
committed
#4 test
1 parent a4de719 commit a74a038

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/test/java/co/stateful/AtomicTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@
3030
package co.stateful;
3131

3232
import co.stateful.mock.MkSttc;
33+
import java.io.IOException;
3334
import java.util.concurrent.Callable;
3435
import org.hamcrest.MatcherAssert;
3536
import org.hamcrest.Matchers;
3637
import 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
}

0 commit comments

Comments
 (0)