Skip to content

Commit

Permalink
Merge pull request #1647 from lukas-krecan/pr/1641
Browse files Browse the repository at this point in the history
#1640 Fix LockAssert.makeAllAssertsPass(true) to not start more than once
  • Loading branch information
lukas-krecan authored Dec 7, 2023
2 parents 3cfc1dd + 19b7cbd commit c83473f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public static class TestHelper {
*/
public static void makeAllAssertsPass(boolean pass) {
if (pass) {
LockAssert.startLock(TEST_LOCK_NAME);
if (!LockAssert.alreadyLockedBy(TEST_LOCK_NAME)) {
LockAssert.startLock(TEST_LOCK_NAME);
}
} else {
if (LockAssert.alreadyLockedBy(TEST_LOCK_NAME)) {
LockAssert.endLock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,15 @@ void assertShouldNotFailIfConfiguredForTests() {
void makeAllAssertsPassShouldNotFail() {
LockAssert.TestHelper.makeAllAssertsPass(false);
}

@Test
void shouldNotStartMoreThanOneTestLock() {
assertThatThrownBy(LockAssert::assertLocked).isInstanceOf(IllegalStateException.class);
LockAssert.TestHelper.makeAllAssertsPass(true);
LockAssert.TestHelper.makeAllAssertsPass(true);

LockAssert.TestHelper.makeAllAssertsPass(false);

assertThatThrownBy(LockAssert::assertLocked).isInstanceOf(IllegalStateException.class);
}
}

0 comments on commit c83473f

Please sign in to comment.