Skip to content

Commit

Permalink
Add currentThread method to KiwiEnvironment (#959)
Browse files Browse the repository at this point in the history
Closes #942
  • Loading branch information
sleberknight authored Apr 24, 2023
1 parent 64c5bb8 commit 03db5be
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/org/kiwiproject/base/DefaultEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public Optional<ProcessHandle> processHandleOfPid(long pid) {
return ProcessHandle.of(pid);
}

@Override
public Thread currentThread() {
return Thread.currentThread();
}

@Override
public void sleep(long milliseconds) throws InterruptedException {
Thread.sleep(milliseconds);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/kiwiproject/base/KiwiEnvironment.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ public interface KiwiEnvironment {
*/
ProcessHandle currentProcessHandle();

/**
* Returns a reference to the currently executing thread object.
*
* @return the currently executing thread
* @see Thread#currentThread()
*/
Thread currentThread();

/**
* Tries to obtain a {@link ProcessHandle} for a process with the given ID. If the process does not exist, then
* an empty Optional is returned.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,11 @@ void shouldReturnEmptyOptional_WhenProcessDoesNotExist() {
}
}

@Test
void shouldReturnCurrentThread() {
assertThat(env.currentThread()).isSameAs(Thread.currentThread());
}

@Test
void testSleep() throws InterruptedException {
long sleepTime = 50;
Expand Down

0 comments on commit 03db5be

Please sign in to comment.