Skip to content

Commit 3be52fc

Browse files
committed
Finish revisions to artifact path handling
1 parent c65852a commit 3be52fc

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

src/main/java/com/nordstrom/automation/junit/ArtifactCollector.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -125,23 +125,7 @@ public Optional<Path> captureArtifact(Throwable reason) {
125125
*/
126126
private Path getCollectionPath() {
127127
Path collectionPath = PathUtils.ReportsDirectory.getPathForObject(getInstance());
128-
Path artifactPath = provider.getArtifactPath(getInstance());
129-
if (artifactPath == null) {
130-
artifactPath = getArtifactPath(getInstance());
131-
}
132-
return collectionPath.resolve(artifactPath);
133-
}
134-
135-
/**
136-
* Get the path at which to store artifacts.
137-
* <p>
138-
* <b>NOTE</b>: The returned path can be either relative or absolute.
139-
*
140-
* @param instance JUnit test class instance
141-
* @return artifact storage path
142-
*/
143-
public static Path getArtifactPath(Object instance) {
144-
return PathUtils.ReportsDirectory.getPathForObject(instance);
128+
return collectionPath.resolve(provider.getArtifactPath(getInstance()));
145129
}
146130

147131
/**

src/main/java/com/nordstrom/automation/junit/ArtifactType.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.nio.file.Path;
44
import org.slf4j.Logger;
55

6+
import com.nordstrom.common.file.PathUtils;
7+
68
/**
79
* This interface defines the contract fulfilled by artifact capture providers. Instances of this interface supply the
810
* scenario-specific implementation for artifact capture through the {@link ArtifactCollector} listener.
@@ -19,7 +21,7 @@
1921
*
2022
* import com.nordstrom.automation.junit.ArtifactType;
2123
*
22-
* public class MyArtifactType implements ArtifactType {
24+
* public class MyArtifactType extends ArtifactType {
2325
*
2426
* private static final String ARTIFACT_PATH = "artifacts";
2527
* private static final String EXTENSION = "txt";
@@ -37,8 +39,8 @@
3739
* }
3840
*
3941
* &#64;Override
40-
* public Page getArtifactPath(Object instance) {
41-
* return ArtifactType.super.getArtifactPath(instance).resolve(ARTIFACT_PATH);
42+
* public Path getArtifactPath(Object instance) {
43+
* return super.getArtifactPath(instance).resolve(ARTIFACT_PATH);
4244
* }
4345
*
4446
* &#64;Override
@@ -66,22 +68,24 @@
6668
* }
6769
* </code></pre>
6870
*/
69-
public interface ArtifactType {
71+
public abstract class ArtifactType {
7072

7173
/**
7274
* Get the SLF4J {@link Logger} for this artifact type.
7375
*
7476
* @return logger for this artifact (may be {@code null})
7577
*/
76-
Logger getLogger();
78+
public Logger getLogger() {
79+
return null;
80+
}
7781

7882
/**
7983
* Determine if artifact capture is available in the specified context.
8084
*
8185
* @param instance JUnit test class instance
8286
* @return 'true' if capture is available; otherwise 'false'
8387
*/
84-
boolean canGetArtifact(Object instance);
88+
public abstract boolean canGetArtifact(Object instance);
8589

8690
/**
8791
* Capture an artifact from the specified context.
@@ -90,23 +94,25 @@ public interface ArtifactType {
9094
* @param reason impetus for capture request; may be 'null'
9195
* @return byte array containing the captured artifact; if capture fails, an empty array is returned
9296
*/
93-
byte[] getArtifact(Object instance, Throwable reason);
97+
public abstract byte[] getArtifact(Object instance, Throwable reason);
9498

9599
/**
96100
* Get the path at which to store artifacts.
97101
* <p>
98102
* <b>NOTE</b>: The returned path can be either relative or absolute.
99103
*
100104
* @param instance JUnit test class instance
101-
* @return artifact storage path; {@code null} to accept default path
105+
* @return artifact storage path
102106
*/
103-
Path getArtifactPath(Object instance);
107+
public Path getArtifactPath(Object instance) {
108+
return PathUtils.ReportsDirectory.getPathForObject(instance);
109+
}
104110

105111
/**
106112
* Get the extension for artifact files of this type.
107113
*
108114
* @return artifact file extension
109115
*/
110-
String getArtifactExtension();
116+
public abstract String getArtifactExtension();
111117

112118
}

src/test/java/com/nordstrom/automation/junit/UnitTestArtifact.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
package com.nordstrom.automation.junit;
22

3-
import java.nio.file.Path;
43
import java.util.Map.Entry;
54
import org.slf4j.Logger;
65
import org.slf4j.LoggerFactory;
76

8-
public class UnitTestArtifact implements ArtifactType {
7+
public class UnitTestArtifact extends ArtifactType {
98

109
private boolean captureDisabled;
1110
private boolean captureCrippled;
@@ -53,11 +52,6 @@ public byte[] getArtifact(Object instance, Throwable reason) {
5352
}
5453
}
5554

56-
@Override
57-
public Path getArtifactPath(Object instance) {
58-
return null;
59-
}
60-
6155
@Override
6256
public String getArtifactExtension() {
6357
return EXTENSION;

0 commit comments

Comments
 (0)