Skip to content

Commit

Permalink
Also run samples via test runner in java-sample
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonScholz committed Oct 15, 2023
1 parent efccdd2 commit c07d9a6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: CI
on: [push, pull_request]

jobs:
jvm:
kotlin-build:
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions java-sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
17 changes: 10 additions & 7 deletions java-sample/src/main/java/io/github/simonscholz/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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"));
}

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions java-sample/src/test/java/io/github/simonscholz/QrCodeTest.java
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit c07d9a6

Please sign in to comment.