diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index 958d7cd..bbbc951 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -3,7 +3,7 @@ name: CI on: [push, pull_request] jobs: - jvm: + kotlin-build: runs-on: ubuntu-latest steps: @@ -48,7 +48,7 @@ jobs: runs-on: ubuntu-latest if: github.repository == 'SimonScholz/qr-code-with-logo' && github.ref == 'refs/heads/main' needs: - - jvm + - kotlin-build - java-sample-different-jdks steps: - uses: actions/checkout@v4 diff --git a/java-sample/build.gradle.kts b/java-sample/build.gradle.kts index ad07c79..c1c569b 100644 --- a/java-sample/build.gradle.kts +++ b/java-sample/build.gradle.kts @@ -14,6 +14,9 @@ repositories { dependencies { implementation("io.github.simonscholz:qr-code-with-logo:0.1.0-SNAPSHOT") + + testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0") + testImplementation("org.junit.jupiter:junit-jupiter-params:5.10.0") } tasks.test { diff --git a/java-sample/src/main/java/io/github/simonscholz/Main.java b/java-sample/src/main/java/io/github/simonscholz/Main.java index 0b8992c..faba3a9 100644 --- a/java-sample/src/main/java/io/github/simonscholz/Main.java +++ b/java-sample/src/main/java/io/github/simonscholz/Main.java @@ -7,7 +7,7 @@ import io.github.simonscholz.qrcode.QrPositionalSquaresConfig; import javax.imageio.ImageIO; -import java.awt.Color; +import java.awt.*; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; @@ -31,9 +31,12 @@ public static void main(final String[] args) throws IOException { final QrCodeApi qrCodeApi = QrCodeFactory.createQrCodeApi(); final Path path = Paths.get(System.getProperty("user.home"), "qr-code-samples"); Files.createDirectories(path); - final var qrCodeDir = path.toAbsolutePath() - .toString(); + final String qrCodeDir = path.toAbsolutePath().toString(); + generateSamples(qrCodeApi, qrCodeDir); + } + + static void generateSamples(QrCodeApi qrCodeApi, String qrCodeDir) throws IOException { createDefaultQrCode(qrCodeApi, qrCodeDir); final URL resource = Main.class.getClassLoader() @@ -60,7 +63,7 @@ public static void main(final String[] args) throws IOException { } private static void createDefaultQrCode(final QrCodeApi qrCodeApi, final String qrCodeDir) throws IOException { - final var qrCode = qrCodeApi.createQrCodeImage(new QrCodeConfig("https://simonscholz.github.io/", DEFAULT_IMG_SIZE)); + final BufferedImage qrCode = qrCodeApi.createQrCodeImage(new QrCodeConfig("https://simonscholz.github.io/", DEFAULT_IMG_SIZE)); ImageIO.write(qrCode, "png", new File(qrCodeDir, "/qr-with-defaults-java.png")); } @@ -119,8 +122,8 @@ private static void decentRedColor(final URL resource, final QrCodeApi qrCodeApi private static void mineCraftCreeperColor(final URL resource, final QrCodeApi qrCodeApi, final String qrCodeDir) throws IOException { final BufferedImage logo = ImageIO.read(resource); - final var brighterGreen = Color.GREEN.brighter(); - final var darkerGreen = Color.GREEN.darker() + final Color brighterGreen = Color.GREEN.brighter(); + final Color darkerGreen = Color.GREEN.darker() .darker() .darker(); @@ -194,7 +197,7 @@ private static void drawQrCodeOnImage(final BufferedImage qrCode, final String q final URL url = Objects.requireNonNull(Main.class.getClassLoader() .getResource("cup.jpg")); final BufferedImage mainImg = ImageIO.read(url); - final var graphics = mainImg.getGraphics(); + final Graphics graphics = mainImg.getGraphics(); graphics.drawImage(qrCode, 330, 600, null); graphics.dispose(); ImageIO.write(mainImg, "png", new File(qrCodeDir, "/transparent-color-java.png")); diff --git a/java-sample/src/main/java/io/github/simonscholz/QrCodeTypesMain.java b/java-sample/src/main/java/io/github/simonscholz/QrCodeTypesMain.java index 9aa2237..83c1522 100644 --- a/java-sample/src/main/java/io/github/simonscholz/QrCodeTypesMain.java +++ b/java-sample/src/main/java/io/github/simonscholz/QrCodeTypesMain.java @@ -28,6 +28,10 @@ public static void main(final String[] args) throws IOException { Files.createDirectories(path); final var qrCodeDir = path.toAbsolutePath().toString(); + generateSamples(qrCodeApi, qrCodeDir); + } + + static void generateSamples(QrCodeApi qrCodeApi, String qrCodeDir) throws IOException { createWithUrl(qrCodeApi, qrCodeDir); createWithGeolocation(qrCodeApi, qrCodeDir); createWithEmail(qrCodeApi, qrCodeDir); diff --git a/java-sample/src/test/java/io/github/simonscholz/QrCodeTest.java b/java-sample/src/test/java/io/github/simonscholz/QrCodeTest.java new file mode 100644 index 0000000..45cae8a --- /dev/null +++ b/java-sample/src/test/java/io/github/simonscholz/QrCodeTest.java @@ -0,0 +1,24 @@ +package io.github.simonscholz; + +import io.github.simonscholz.qrcode.QrCodeApi; +import io.github.simonscholz.qrcode.QrCodeFactory; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.io.IOException; +import java.nio.file.Path; + +public class QrCodeTest { + + @Test + public void testMain(@TempDir Path tempDir) throws IOException { + QrCodeApi qrCodeApi = QrCodeFactory.createQrCodeApi(); + Main.generateSamples(qrCodeApi, tempDir.toAbsolutePath().toString()); + } + + @Test + public void testQrCodeTypesMain(@TempDir Path tempDir) throws IOException { + QrCodeApi qrCodeApi = QrCodeFactory.createQrCodeApi(); + QrCodeTypesMain.generateSamples(qrCodeApi, tempDir.toAbsolutePath().toString()); + } +}