diff --git a/core-java-modules/core-java-os-2/src/test/java/com/baeldung/java9/process/ProcessWaitTest.java b/core-java-modules/core-java-os-2/src/test/java/com/baeldung/java9/process/ProcessWaitTest.java new file mode 100644 index 000000000000..e1475960108f --- /dev/null +++ b/core-java-modules/core-java-os-2/src/test/java/com/baeldung/java9/process/ProcessWaitTest.java @@ -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(); + }); + } +} diff --git a/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/stringformat/StringFormatUnitTest.java b/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/stringformat/StringFormatUnitTest.java index 16cf87a26ccd..8a86f2b51d56 100644 --- a/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/stringformat/StringFormatUnitTest.java +++ b/core-java-modules/core-java-string-apis-2/src/test/java/com/baeldung/stringformat/StringFormatUnitTest.java @@ -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)); + } }