Skip to content

Commit

Permalink
Make SpecFolderCollector a regular class
Browse files Browse the repository at this point in the history
  • Loading branch information
picimako committed Oct 15, 2023
1 parent 7a72e81 commit 5cb5080
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
@Service(Service.Level.PROJECT)
public final class NoopResourceManager extends TerraResourceManager {

private static final SpecFolderCollector NOOP = new SpecFolderCollector(null);

//Required for project service creation
public NoopResourceManager(Project project) {
}
Expand Down Expand Up @@ -63,7 +65,7 @@ public ScreenshotContextParser screenshotContextParser(String contextSeparator)

@Override
public SpecFolderCollector specFolderCollector() {
return dir -> null;
return NOOP;
}

@Override
Expand Down
27 changes: 12 additions & 15 deletions src/main/java/com/picimako/terra/wdio/SpecFolderCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
package com.picimako.terra.wdio;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

import com.intellij.openapi.vfs.VirtualFile;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Collects spec folders based on image type.
*/
@FunctionalInterface
public interface SpecFolderCollector {
@RequiredArgsConstructor
public final class SpecFolderCollector {

/**
* Retrieves the folder type based on the {@code [type]/locale/browser_viewport/spec} folder structure.
*/
SpecFolderCollector TERRA_TOOLKIT_SPEC_COLLECTOR = dir -> dir.getParent().getParent().getParent().getName();
/**
* Retrieves the folder type based on the {@code [type]/theme/locale/browser_viewport/spec} folder structure.
* Returns in which image type the argument folder is located: diff, latest, reference.
*/
SpecFolderCollector TERRA_FUNCTIONAL_TESTING_SPEC_COLLECTOR = dir -> dir.getParent().getParent().getParent().getParent().getName();
@Nullable("Only by the no-op collector.")
@Getter
private final Function<VirtualFile, String> folderType;

/**
* Collect spec folders from within the provided set of files and folders (effectively everything from) the wdio
Expand All @@ -33,15 +35,10 @@ public interface SpecFolderCollector {
* @return the stream of matching spec folders
*/
@NotNull
default Stream<VirtualFile> collectSpecFoldersForTypeInside(@NotNull String imageType, @NotNull List<VirtualFile> filesAndFoldersInWdioRoot) {
public Stream<VirtualFile> collectSpecFoldersForTypeInside(@NotNull String imageType, @NotNull List<VirtualFile> filesAndFoldersInWdioRoot) {
return filesAndFoldersInWdioRoot.stream()
.filter(VirtualFile::isDirectory)
.filter(dir -> dir.getName().endsWith("-spec"))
.filter(dir -> imageType.equals(getFolderType(dir)));
.filter(dir -> imageType.equals(folderType.apply(dir)));
}

/**
* Returns in which image type the argument folder is located: diff, latest, reference.
*/
String getFolderType(VirtualFile dir);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
@Service(Service.Level.PROJECT)
public final class TerraFunctionalTestingManager extends TerraResourceManager {

/**
* Retrieves the folder type based on the {@code [type]/theme/locale/browser_viewport/spec} folder structure.
*/
private static final SpecFolderCollector TERRA_FUNCTIONAL_TESTING_SPEC_COLLECTOR =
new SpecFolderCollector(dir -> dir.getParent().getParent().getParent().getParent().getName());
private ScreenshotContextParser contextParserWithSeparator;

//Required for project service creation
Expand All @@ -42,7 +47,7 @@ public ScreenshotContextParser screenshotContextParser(String contextSeparator)

@Override
public SpecFolderCollector specFolderCollector() {
return SpecFolderCollector.TERRA_FUNCTIONAL_TESTING_SPEC_COLLECTOR;
return TERRA_FUNCTIONAL_TESTING_SPEC_COLLECTOR;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
@Service(Service.Level.PROJECT)
public final class TerraToolkitManager extends TerraResourceManager {

/**
* Retrieves the folder type based on the {@code [type]/locale/browser_viewport/spec} folder structure.
*/
private static final SpecFolderCollector TERRA_TOOLKIT_SPEC_COLLECTOR = new SpecFolderCollector(dir -> dir.getParent().getParent().getParent().getName());
private ScreenshotContextParser contextParserWithSeparator;

//Required for project service creation
Expand All @@ -42,7 +46,7 @@ public ScreenshotContextParser screenshotContextParser(String contextSeparator)

@Override
public SpecFolderCollector specFolderCollector() {
return SpecFolderCollector.TERRA_TOOLKIT_SPEC_COLLECTOR;
return TERRA_TOOLKIT_SPEC_COLLECTOR;
}

@Override
Expand Down

0 comments on commit 5cb5080

Please sign in to comment.