Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
beatngu13 committed Jan 4, 2024
2 parents deadf57 + c10d38a commit f69a23b
Show file tree
Hide file tree
Showing 17 changed files with 196 additions and 148 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ jobs:

steps:
- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: artifacts

Expand Down
31 changes: 19 additions & 12 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<groupId>com.github.beatngu13</groupId>
<artifactId>pdfzoomwizard</artifactId>
<version>0.12.1</version>
<version>0.13.0</version>

<name>PDF Zoom Wizard</name>

Expand All @@ -17,6 +17,7 @@
<project.resources.sourceEncoding>${encoding}</project.resources.sourceEncoding>
<java.version>17</java.version>
<javafx.version>20.0.2</javafx.version>
<mockito.version>5.8.0</mockito.version>
<mainClass>com.github.beatngu13.pdfzoomwizard.LauncherWrapper</mainClass>
<sonar.projectKey>beatngu13_pdf-zoom-wizard</sonar.projectKey>
<sonar.organization>beatngu13</sonar.organization>
Expand Down Expand Up @@ -52,43 +53,49 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.4.11</version>
<version>1.4.14</version>
</dependency>

<!-- test -->

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.10.0</version>
<version>5.10.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.24.2</version>
<version>3.25.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.6.0</version>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.approvaltests</groupId>
<artifactId>approvaltests</artifactId>
<version>22.2.0</version>
<version>22.3.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>8.0.1</version>
<version>8.0.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -114,7 +121,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<version>3.12.1</version>
<configuration>
<release>${java.version}</release>
</configuration>
Expand All @@ -123,7 +130,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.3</version>
<configuration>
<properties>
<configurationParameters>
Expand All @@ -137,7 +144,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.3</version>
<configuration>
<!-- see https://stackoverflow.com/a/15567782 -->
<reportsDirectory>${project.build.directory}/surefire-reports/</reportsDirectory>
Expand Down Expand Up @@ -192,7 +199,7 @@
<plugin>
<groupId>com.gluonhq</groupId>
<artifactId>gluonfx-maven-plugin</artifactId>
<version>1.0.21</version>
<version>1.0.22</version>
<configuration>
<mainClass>${mainClass}</mainClass>
<javaStaticSdkVersion>${java.version}</javaStaticSdkVersion>
Expand All @@ -214,7 +221,7 @@
<plugin>
<groupId>com.amashchenko.maven.plugin</groupId>
<artifactId>gitflow-maven-plugin</artifactId>
<version>1.20.0</version>
<version>1.21.0</version>
<configuration>
<commitDevelopmentVersionAtStart>true</commitDevelopmentVersionAtStart>
<useSnapshotInRelease>true</useSnapshotInRelease>
Expand Down
2 changes: 1 addition & 1 deletion scripts/start-hotfix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -x

./mvnw -B gitflow:hotfix-start
./mvnw -B gitflow:hotfix-start -DhotfixBranch="$1"
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ private void modifyFile(File file) {
* @param bookmarks Bookmarks to be modified.
*/
void modifyBookmarks(Bookmarks bookmarks) {
Bookmark previous = null;
for (Bookmark bookmark : bookmarks) {
var children = bookmark.getBookmarks();
// Bookmarks#iterator() might be endless.
if (bookmark.equals(previous)) {
break;
}
Bookmarks children = bookmark.getBookmarks();
// Size might be positive (bookmark open) or negative (bookmark closed).
if (children.size() != 0) {
modifyBookmarks(children);
}
modifyBookmark(bookmark);
previous = bookmark;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* Provides a JavaFX-based Wizard UI.
Expand All @@ -31,6 +33,10 @@ public class MainViewController {

private static final Logger logger = LoggerFactory.getLogger(MainViewController.class);

/**
* <code>ExecutorService</code> for running {@link Wizard} tasks.
*/
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
/**
* Provides the last directory for {@link #directoryChooser} and
* {@link #fileChooser}.
Expand Down Expand Up @@ -204,11 +210,12 @@ private boolean logAndShow(String msg) {
* @return Confirmation message for directory/file to be overwritten/copied.
*/
private String getConfirmationMessage() {
var prefix = multipleMode
? "All files in '" + root.getAbsolutePath() + "' and its enclosing subdirectories will be "
: "File '" + root.getAbsolutePath() + "' will be ";
var prefix = (multipleMode
? "All files in '%s' and its enclosing subdirectories will be "
: "File '%s' will be ")
.formatted(root.getAbsolutePath());
var infix = copyCheckBox.isSelected() ? "copied." : "overwritten.";
var suffix = "\n\nAre you sure to proceed?";
var suffix = System.lineSeparator().repeat(2) + "Are you sure to proceed?";
return prefix + infix + suffix;
}

Expand All @@ -219,11 +226,9 @@ private String getConfirmationMessage() {
private void run() {
var filenameInfix = copyCheckBox.isSelected() ? copyTextField.getText() : null;
var wizard = new Wizard(root, filenameInfix, zoomChoiceBox.getValue());
var thread = new Thread(wizard);
// Can't be bound because infoText is also set within here.
wizard.messageProperty().addListener((observable, oldValue, newValue) -> infoText.setText(newValue));
thread.setDaemon(true);
thread.start();
executorService.submit(wizard);
}

}
53 changes: 0 additions & 53 deletions src/test/java/com/github/beatngu13/pdfzoomwizard/TestUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
package com.github.beatngu13.pdfzoomwizard.core;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.pdfclown.documents.interaction.navigation.document.Bookmark;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class BookmarkUtilTest {

@Mock
Bookmark bookmark;

@Test
void bookmark_title_should_be_used_when_available() {
var title = "foo";
var bookmark = mock(Bookmark.class);
when(bookmark.getTitle()).thenReturn(title);
assertThat(BookmarkUtil.getTitle(bookmark)).isEqualTo(title);
}

@Test
void fallback_title_should_be_used_when_exception_occurs() {
var bookmark = mock(Bookmark.class);
when(bookmark.getTitle()).thenThrow(RuntimeException.class);
assertThat(BookmarkUtil.getTitle(bookmark)).isEqualTo(BookmarkUtil.BOOKMARK_TITLE_FALLBACK);
}
Expand Down
28 changes: 10 additions & 18 deletions src/test/java/com/github/beatngu13/pdfzoomwizard/core/WizardIT.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.github.beatngu13.pdfzoomwizard.core;

import com.github.beatngu13.pdfzoomwizard.TestUtil;
import com.itextpdf.kernel.pdf.PdfObject;
import org.approvaltests.Approvals;
import org.approvaltests.namer.NamedEnvironment;
import org.approvaltests.namer.NamerFactory;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand All @@ -17,7 +13,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
Expand All @@ -40,32 +35,29 @@ void setUp(@TempDir Path temp) throws Exception {
}

@ParameterizedTest
@EnumSource(Zoom.class)
@EnumSource
void zoom_should_be_applied_properly(Zoom zoom) {
var zoomName = TestUtil.toStringNormalized(zoom);
try (NamedEnvironment env = NamerFactory.withParameters(zoomName)) {
new Wizard(pdf, null, zoom).call();
List<PdfObject> pdfObjects = TestUtil.getAllPdfObjects(pdf);
Approvals.verify(pdfObjects);
}
var zoomName = zoom.name().toLowerCase();
new Wizard(pdf, null, zoom).call();
var bookmarks = WizardITUtil.getBookmarks(pdf);
Approvals.verifyAll(bookmarks.toArray(), Object::toString, Approvals.NAMES.withParameters(zoomName));
}

@Test
void should_overwrite_pdf_if_infix_is_null() {
new Wizard(pdf, null, Zoom.INHERIT_ZOOM).call();
assertThat(pdf.getParentFile().listFiles())
.extracting(File::getName)
.containsExactly(pdfName);
assertThat(pdf.getParentFile())
.isDirectoryContaining(file -> file.getName().equals(pdfName));
}

@Test
void should_copy_pdf_if_infix_is_not_null() {
var pdfInfix = "-infix";
new Wizard(pdf, pdfInfix, Zoom.INHERIT_ZOOM).call();
var pdfCopyName = pdfPrefix + pdfInfix + pdfSuffix;
assertThat(pdf.getParentFile().listFiles())
.extracting(File::getName)
.containsExactlyInAnyOrder(pdfName, pdfCopyName);
assertThat(pdf.getParentFile())
.isDirectoryContaining(file -> file.getName().equals(pdfName))
.isDirectoryContaining(file -> file.getName().equals(pdfCopyName));
}

}
Expand Down
Loading

0 comments on commit f69a23b

Please sign in to comment.