-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
306 additions
and
254 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 6 additions & 27 deletions
33
src/test/java/com/github/stickerifier/stickerify/ResourceHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,19 @@ | ||
package com.github.stickerifier.stickerify; | ||
|
||
import static org.junit.jupiter.api.Assumptions.abort; | ||
import static org.junit.jupiter.api.Assumptions.assumeTrue; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.image.BufferedImage; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
public final class ResourceHelper { | ||
|
||
private final File directory; | ||
|
||
public ResourceHelper(File directory) { | ||
this.directory = directory; | ||
} | ||
|
||
public File createImage(int width, int height, String extension) { | ||
var image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); | ||
var file = new File(directory, "%d x %d.%s".formatted(width, height, extension)); | ||
|
||
try { | ||
ImageIO.write(image, extension, file); | ||
} catch (IOException e) { | ||
abort("Image could not be written to file [%s].".formatted(file.getName())); | ||
} finally { | ||
image.flush(); | ||
} | ||
|
||
return file; | ||
} | ||
|
||
public File loadResource(String filename) { | ||
var resource = getClass().getClassLoader().getResource(filename); | ||
public static File loadResource(String filename) { | ||
var resource = ResourceHelper.class.getClassLoader().getResource(filename); | ||
assumeTrue(resource != null, "Test resource [%s] not found.".formatted(filename)); | ||
|
||
return new File(resource.getFile()); | ||
} | ||
|
||
private ResourceHelper() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
Oops, something went wrong.