Skip to content

Commit

Permalink
lukas-krecan#1640 Fix LockAssert.makeAllAssertsPass(true) to not star…
Browse files Browse the repository at this point in the history
…t more than one test lock
  • Loading branch information
fabianlinz authored and Fabian Linz committed Dec 7, 2023
1 parent 0d0eecc commit c4fe2f9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
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 @@ -22,6 +22,8 @@

import java.time.Duration;
import java.util.Optional;

import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

class LockAssertTest {
Expand Down Expand Up @@ -67,17 +69,32 @@ void shouldWorkWithNestedLocks() {
assertThatThrownBy(LockAssert::assertLocked).isInstanceOf(IllegalStateException.class);
}

@Test
void assertShouldNotFailIfConfiguredForTests() {
LockAssert.TestHelper.makeAllAssertsPass(true);
LockAssert.assertLocked();
@Nested
class TestHelper {
@Test
void assertShouldNotFailIfConfiguredForTests() {
LockAssert.TestHelper.makeAllAssertsPass(true);
LockAssert.assertLocked();

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

@Test
void makeAllAssertsPassShouldNotFail() {
LockAssert.TestHelper.makeAllAssertsPass(false);
@Test
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 c4fe2f9

Please sign in to comment.