Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.baeldung.java9.process;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;

class ProcessWaitTest {

@Test
void givenAProcess_whenUsingWaitFor_thenNoExceptionThrown() {
// Code that interacts with a process should not throw IllegalMonitorStateException.
assertDoesNotThrow(() -> {
Process process = new ProcessBuilder("notepad.exe").start();
int exitCode = process.waitFor();
});
}

@Test
void givenAProcess_whenUsingWaitWithoutSynchronization_thenExceptionThrown() {
assertThrows(IllegalMonitorStateException.class, () -> {
Process process = new ProcessBuilder("notepad.exe").start();
process.wait();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,16 @@ public void whenCurrencyFormatWithLocales_thenCorrect() {
String frenchFormatted = frenchCurrencyFormat.format(1000);
assertEquals("1 000,00 €", frenchFormatted);
}

private String padIntegerWithZeros(int number, int width) {

return String.format("%0" + width + "d", number);
}

@Test
public void givenAnInteger_whenPaddingWithZeros_thanIntegerGetsPadded() {

assertEquals("00000001", padIntegerWithZeros(1, 8));
assertEquals("-0000001", padIntegerWithZeros(-1, 8));
}
}