-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c54155e
commit 5264118
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/test/java/io/github/pixee/security/ExecuteWithinTimeoutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.pixee.security; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.regex.Pattern; | ||
import java.util.stream.Stream; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
final class ExecuteWithTimeoutTest { | ||
|
||
@Test | ||
void it_executes_within_timeout_and_returns(){ | ||
var pat = Pattern.compile("string"); | ||
String input = "some very long string"; | ||
var matcher = pat.matcher(input); | ||
boolean result = ExecuteWithTimeout.executeWithTimeout(() -> matcher.matches(), 5000); | ||
assertThat(result, is(true)); | ||
} | ||
|
||
@Test | ||
void it_throws_exception_due_to_timeout(){ | ||
assertThrows( | ||
RuntimeException.class, | ||
() -> ExecuteWithTimeout.executeWithTimeout(() -> matcher.matches(), 0) | ||
); | ||
} | ||
|
||
} |