-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Allow snapshots to be updated by toggling `update-snapshot` property in `snapshot.properties`. - Deprecate the passing of system property `-PupdateSnapshot`. - Add some API deprecation logs for V5
- Loading branch information
Showing
16 changed files
with
259 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
java-snapshot-testing-core/src/main/java/au/com/origin/snapshots/logging/LoggingHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package au.com.origin.snapshots.logging; | ||
|
||
import org.slf4j.Logger; | ||
|
||
public class LoggingHelper { | ||
|
||
public static void deprecatedV5(Logger log, String message) { | ||
log.warn( | ||
"Deprecation Warning:\n " + message + "\n\nThis feature will be removed in version 5.X"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
java-snapshot-testing-core/src/test/java/au/com/origin/snapshots/UpdateSnapshotTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package au.com.origin.snapshots; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import au.com.origin.snapshots.config.BaseSnapshotConfig; | ||
import au.com.origin.snapshots.config.SnapshotConfig; | ||
import au.com.origin.snapshots.exceptions.SnapshotMatchException; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Optional; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class UpdateSnapshotTest { | ||
|
||
@BeforeEach | ||
public void beforeEach() throws Exception { | ||
File file = | ||
new File("src/test/java/au/com/origin/snapshots/__snapshots__/UpdateSnapshotTest.snap"); | ||
String content = | ||
"au.com.origin.snapshots.UpdateSnapshotTest.canUpdateAllSnapshots=[\n" | ||
+ "OLD\n" | ||
+ "]\n" | ||
+ "\n" | ||
+ "\n" | ||
+ "au.com.origin.snapshots.UpdateSnapshotTest.canUpdateClassNameSnapshots=[\n" | ||
+ "OLD\n" | ||
+ "]\n" | ||
+ "\n" | ||
+ "\n" | ||
+ "au.com.origin.snapshots.UpdateSnapshotTest.canUpdateNoSnapshots=[\n" | ||
+ "OLD\n" | ||
+ "]"; | ||
Path parentDir = file.getParentFile().toPath(); | ||
if (!Files.exists(parentDir)) { | ||
Files.createDirectories(parentDir); | ||
} | ||
Files.write(file.toPath(), content.getBytes(StandardCharsets.UTF_8)); | ||
} | ||
|
||
@Test | ||
void canUpdateAllSnapshots(TestInfo testInfo) throws IOException { | ||
SnapshotConfig config = | ||
new BaseSnapshotConfig() { | ||
@Override | ||
public Optional<String> updateSnapshot() { | ||
return Optional.of(""); | ||
} | ||
}; | ||
SnapshotVerifier snapshotVerifier = | ||
new SnapshotVerifier(config, testInfo.getTestClass().get(), false); | ||
Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); | ||
expect.toMatchSnapshot("NEW"); | ||
snapshotVerifier.validateSnapshots(); | ||
|
||
String content = | ||
new String( | ||
Files.readAllBytes( | ||
Paths.get( | ||
"src/test/java/au/com/origin/snapshots/__snapshots__/UpdateSnapshotTest.snap")), | ||
StandardCharsets.UTF_8); | ||
Assertions.assertThat(content) | ||
.isEqualTo( | ||
"au.com.origin.snapshots.UpdateSnapshotTest.canUpdateAllSnapshots=[\n" | ||
+ "NEW\n" | ||
+ "]\n" | ||
+ "\n" | ||
+ "\n" | ||
+ "au.com.origin.snapshots.UpdateSnapshotTest.canUpdateClassNameSnapshots=[\n" | ||
+ "OLD\n" | ||
+ "]\n" | ||
+ "\n" | ||
+ "\n" | ||
+ "au.com.origin.snapshots.UpdateSnapshotTest.canUpdateNoSnapshots=[\n" | ||
+ "OLD\n" | ||
+ "]"); | ||
} | ||
|
||
@Test | ||
void canUpdateNoSnapshots(TestInfo testInfo) { | ||
SnapshotConfig config = | ||
new BaseSnapshotConfig() { | ||
@Override | ||
public Optional<String> updateSnapshot() { | ||
return Optional.empty(); | ||
} | ||
}; | ||
SnapshotVerifier snapshotVerifier = | ||
new SnapshotVerifier(config, testInfo.getTestClass().get(), false); | ||
Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); | ||
assertThrows(SnapshotMatchException.class, () -> expect.toMatchSnapshot("FOOBAR")); | ||
} | ||
|
||
@Test | ||
public void canUpdateNewSnapshots() { | ||
SnapshotConfig config = | ||
new BaseSnapshotConfig() { | ||
@Override | ||
public Optional<String> updateSnapshot() { | ||
return Optional.of("new"); | ||
} | ||
}; | ||
|
||
// TODO Pending Implementation | ||
} | ||
|
||
@Test | ||
public void canUpdateClassNameSnapshots(TestInfo testInfo) throws IOException { | ||
SnapshotConfig config = | ||
new BaseSnapshotConfig() { | ||
@Override | ||
public Optional<String> updateSnapshot() { | ||
return Optional.of("UpdateSnapshotTest"); | ||
} | ||
}; | ||
SnapshotVerifier snapshotVerifier = | ||
new SnapshotVerifier(config, testInfo.getTestClass().get(), false); | ||
Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); | ||
expect.toMatchSnapshot("NEW"); | ||
snapshotVerifier.validateSnapshots(); | ||
|
||
String content = | ||
new String( | ||
Files.readAllBytes( | ||
Paths.get( | ||
"src/test/java/au/com/origin/snapshots/__snapshots__/UpdateSnapshotTest.snap")), | ||
StandardCharsets.UTF_8); | ||
Assertions.assertThat(content) | ||
.isEqualTo( | ||
"au.com.origin.snapshots.UpdateSnapshotTest.canUpdateAllSnapshots=[\n" | ||
+ "OLD\n" | ||
+ "]\n" | ||
+ "\n" | ||
+ "\n" | ||
+ "au.com.origin.snapshots.UpdateSnapshotTest.canUpdateClassNameSnapshots=[\n" | ||
+ "NEW\n" | ||
+ "]\n" | ||
+ "\n" | ||
+ "\n" | ||
+ "au.com.origin.snapshots.UpdateSnapshotTest.canUpdateNoSnapshots=[\n" | ||
+ "OLD\n" | ||
+ "]"); | ||
} | ||
} |
Oops, something went wrong.