File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
main/java/net/javacrumbs/shedlock/core
test/java/net/javacrumbs/shedlock/core Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -47,4 +47,22 @@ public static void assertLocked() {
47
47
throw new IllegalStateException ("The task is not locked." );
48
48
}
49
49
}
50
+
51
+ static class TestHelper {
52
+ /**
53
+ * If pass is set to true, all LockAssert.assertLocked calls in current thread will pass.
54
+ * To be used in unit tests only
55
+ *
56
+ * <code>
57
+ * LockAssert.TestHelper.makeAllAssertsPass(true)
58
+ * </code>
59
+ */
60
+ public static void makeAllAssertsPass (boolean pass ) {
61
+ if (pass ) {
62
+ LockAssert .startLock ("net.javacrumbs.shedlock.core.test-lock" );
63
+ } else {
64
+ LockAssert .endLock ();
65
+ }
66
+ }
67
+ }
50
68
}
Original file line number Diff line number Diff line change 2
2
3
3
import org .junit .jupiter .api .Test ;
4
4
5
- import java .time .Instant ;
6
5
import java .util .Optional ;
7
6
8
7
import static org .assertj .core .api .Assertions .assertThatThrownBy ;
@@ -29,4 +28,12 @@ void assertLockedShouldNotFailIfLockHeld() {
29
28
);
30
29
}
31
30
31
+ @ Test
32
+ void assertShouldNotFailIfConfiguredForTests () {
33
+ LockAssert .TestHelper .makeAllAssertsPass (true );
34
+ LockAssert .assertLocked ();
35
+
36
+ LockAssert .TestHelper .makeAllAssertsPass (false );
37
+ assertThatThrownBy (LockAssert ::assertLocked ).isInstanceOf (IllegalStateException .class );
38
+ }
32
39
}
You can’t perform that action at this time.
0 commit comments