Skip to content

Commit

Permalink
Add test for PathMigrator
Browse files Browse the repository at this point in the history
  • Loading branch information
huangsam committed Nov 30, 2024
1 parent 764dbe3 commit 6c8ab73
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/test/java/io/huangsam/photohaul/TestPathBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import java.nio.file.Path;

public class TestPathBase {
private static final Path TEST_RESOURCES = Path.of("src/test/resources");

protected static Path getStaticResources() {
return Path.of("src/test/resources/static");
return TEST_RESOURCES.resolve("static");
}

protected static Path getTempResources() {
return TEST_RESOURCES.resolve("temp");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.huangsam.photohaul.migration;

import io.huangsam.photohaul.TestPathBase;
import io.huangsam.photohaul.traversal.PhotoPathVisitor;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

import java.nio.file.StandardCopyOption;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class TestPathMigrator extends TestPathBase {
@Test
void testMigratePhotos() {
PhotoPathVisitor pathVisitor = new PhotoPathVisitor();
pathVisitor.visitPhoto(getStaticResources().resolve("bauerlite.jpg"));
pathVisitor.visitPhoto(getStaticResources().resolve("salad.jpg"));

PathMigrator pathMigrator = new PathMigrator(
getTempResources(), StandardCopyOption.REPLACE_EXISTING, new PhotoResolver(List.of()));
pathMigrator.migratePhotos(pathVisitor.getPhotos());

assertEquals(2, pathMigrator.getSuccessCount());
assertEquals(0, pathMigrator.getFailureCount());
}

@AfterAll
static void tearDown() {
PhotoPathVisitor pathVisitor = new PhotoPathVisitor();
pathVisitor.visitPhoto(getTempResources().resolve("bauerlite.jpg"));
pathVisitor.visitPhoto(getTempResources().resolve("salad.jpg"));

PathMigrator pathMigrator = new PathMigrator(
getStaticResources(), StandardCopyOption.REPLACE_EXISTING, new PhotoResolver(List.of()));
pathMigrator.migratePhotos(pathVisitor.getPhotos());
}
}
3 changes: 3 additions & 0 deletions src/test/resources/temp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.jpg
*.jpeg
*.png
Empty file.

0 comments on commit 6c8ab73

Please sign in to comment.