Commit b15155dd by Facundo Javier Gelatti

Extract methods to Resources class

1 parent 78712b7a
......@@ -17,6 +17,7 @@ import java.io.File;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.stegosuite.Resources.pathOf;
public class EmbeddingAndExtractingTest {
......@@ -30,9 +31,7 @@ public class EmbeddingAndExtractingTest {
@After
public void tearDown() throws Exception {
if (outputPath != null) {
new File(outputPath).delete();
}
Resources.delete(outputPath);
}
@Test
......@@ -92,10 +91,6 @@ public class EmbeddingAndExtractingTest {
presenter.extractNotifying(new EmbeddingProgress(), password);
}
private String pathOf(String imageName) {
return getClass().getClassLoader().getResource(imageName).getPath();
}
private StegosuitePresenter getPresenterFor(String imagePath) throws SteganoImageException {
ImageFormat image = ImageFormat.getImageFormat(imagePath);
return new StegosuitePresenter(image, ui);
......
......@@ -4,25 +4,25 @@ import org.eclipse.swt.graphics.ImageData;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.stegosuite.application.StegosuitePresenter;
import org.stegosuite.application.StegosuiteUI;
import org.stegosuite.image.embedding.EmbeddingProgress;
import org.stegosuite.image.embedding.Visualizer;
import org.stegosuite.image.format.ImageFormat;
import org.stegosuite.model.exception.SteganoEmbedException;
import org.stegosuite.model.exception.SteganoExtractException;
import org.stegosuite.model.exception.SteganoImageException;
import org.stegosuite.application.StegosuitePresenter;
import org.stegosuite.application.StegosuiteUI;
import org.stegosuite.model.payload.block.FileBlock;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Observable;
import java.util.Observer;
import static org.junit.Assert.*;
import static org.stegosuite.Resources.pathOf;
public class PresenterTest implements StegosuiteUI, Observer {
private static final String IMAGE_NAME = "snow.bmp";
......@@ -57,7 +57,7 @@ public class PresenterTest implements StegosuiteUI, Observer {
@After
public void tearDown() throws Exception {
delete(EMBEDDED_IMAGE);
Resources.delete(EMBEDDED_IMAGE);
}
@Test
......@@ -143,20 +143,6 @@ public class PresenterTest implements StegosuiteUI, Observer {
return getImage(image).getImageData();
}
private static String pathOf(String fileName) {
URL resourceURL = PresenterTest.class.getClassLoader().getResource(fileName);
if (resourceURL == null)
throw new RuntimeException("The resource " + fileName + " does not exist");
return resourceURL.getPath();
}
private static void delete(String filename) {
try {
new File(pathOf(filename)).delete();
} catch (Exception ignored) {}
}
@Override
public void showEmbeddingError(SteganoEmbedException e) {
throw new RuntimeException(e);
......
package org.stegosuite;
import com.sun.org.apache.regexp.internal.RE;
import java.io.File;
import java.net.URL;
public class Resources {
public static String pathOf(String fileName) {
URL resourceURL = Resources.class.getClassLoader().getResource(fileName);
if (resourceURL == null)
throw new RuntimeException("The resource " + fileName + " does not exist");
return resourceURL.getPath();
}
static void delete(String filename) {
try {
new File(pathOf(filename)).delete();
} catch (Exception ignored) {}
}
}
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!