Refactor Screenshot examples

This commit is contained in:
Grzegorz Piwowarek 2016-10-20 23:10:14 +02:00
parent cdbd83e851
commit fd1a5796a9
3 changed files with 18 additions and 34 deletions

View File

@ -7,20 +7,17 @@ import java.io.File;
public class Screenshot {
private String filePath;
private String filenamePrefix;
private String fileType;
private int timeToWait;
private final String filePath;
private final String filenamePrefix;
private final String fileType;
public Screenshot(String filePath, String filenamePrefix,
String fileType, int timeToWait) {
public Screenshot(String filePath, String filenamePrefix, String fileType) {
this.filePath = filePath;
this.filenamePrefix = filenamePrefix;
this.fileType = fileType;
this.timeToWait = timeToWait;
}
public void getScreenshot() throws Exception {
public void getScreenshot(int timeToWait) throws Exception {
Thread.sleep(timeToWait);
Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
Robot robot = new Robot();

View File

@ -1,34 +1,21 @@
package com.baeldung.printscreen;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;
public class ScreenshotTest {
private Screenshot screenshot;
private String filePath;
private String fileName;
private String fileType;
private File file;
@Before
public void setUp() throws Exception {
filePath = "";
fileName = "Screenshot";
fileType = "jpg";
file = new File(filePath + fileName + "." + fileType);
screenshot = new Screenshot(filePath, fileName, fileType, 2000);
}
private Screenshot screenshot = new Screenshot("", "Screenshot", "jpg");
private File file = new File("Screenshot.jpg");
@Test
public void testGetScreenshot() throws Exception {
screenshot.getScreenshot();
screenshot.getScreenshot(2000);
assertTrue(file.exists());
}

View File

@ -1,20 +1,20 @@
package org.baeldung.ehcache;
import static org.junit.Assert.*;
import org.baeldung.ehcache.calculator.SquaredCalculator;
import org.baeldung.ehcache.config.CacheHelper;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class SquareCalculatorTest {
SquaredCalculator squaredCalculator = new SquaredCalculator();
CacheHelper cacheHelper = new CacheHelper();
private SquaredCalculator squaredCalculator = new SquaredCalculator();
private CacheHelper cacheHelper = new CacheHelper();
@Before
public void setup() {
squaredCalculator.setCache(cacheHelper);
}
@Test