Merge pull request #10371 from Maiklins/Java-2824-Fix-Tests-in-Java-9-and-above-modules

Java 2824 fix tests in java 9 and above modules
This commit is contained in:
Loredana Crusoveanu 2021-01-02 14:16:06 +02:00 committed by GitHub
commit d04f47df10
4 changed files with 22 additions and 14 deletions

View File

@ -6,8 +6,7 @@ import java.util.logging.Logger;
public class OutputStreamExample {
public static void main(String[] args) {
Logger log = Logger.getLogger(OutputStreamExample.class.getName());
log.log(Level.INFO, Integer.toString(sum(1,2)));
System.out.println(sum(1,2));
}
public static int sum(int a, int b) {

View File

@ -5,10 +5,10 @@ import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.String;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.lang.Integer;
@ -88,4 +88,21 @@ class ProcessUnderstandingUnitTest {
.filter(ph -> (ph.pid() > 10000 && ph.pid() < 50000))
.count()) > 0);
}
@Test
public void givenSourceProgram_whenReadingInputStream_thenFirstLineEquals3() throws IOException {
Runtime.getRuntime()
.exec("javac -cp src src/main/java/com/baeldung/java9/process/OutputStreamExample.java"
.replace("/", File.separator));
Process process = Runtime.getRuntime()
.exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample"
.replace("/", File.separator));
BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
int value = Integer.parseInt(output.readLine());
assertEquals(3, value);
}
}

View File

@ -9,11 +9,13 @@ import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import static org.junit.Assert.assertTrue;
@Ignore
public class ScreenshotUnitTest {
@Test
@ -43,7 +45,6 @@ public class ScreenshotUnitTest {
// This methods needs a component as a parameter and can only be run from an application with a GUI
@Test
@Disabled
public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception {
Rectangle componentRect = component.getBounds();
BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB);

View File

@ -18,15 +18,6 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic;
@PrepareForTest({ LocalDateTime.class })
public class LocalDateTimeUnitTest {
@Test
public void givenLocalDateTimeMock_whenNow_thenGetFixedLocalDateTime() {
Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC"));
String dateTimeExpected = "2014-12-22T10:15:30";
LocalDateTime now = LocalDateTime.now(clock);
assertThat(now).isEqualTo(dateTimeExpected);
}
@Test
public void givenFixedClock_whenNow_thenGetFixedLocalDateTime() {
Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC"));