|
1 | 1 | package au.com.origin.snapshots;
|
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 4 | + |
3 | 5 | import au.com.origin.snapshots.annotations.SnapshotName;
|
4 | 6 | import au.com.origin.snapshots.config.BaseSnapshotConfig;
|
| 7 | +import au.com.origin.snapshots.exceptions.ReservedWordException; |
5 | 8 | import org.junit.jupiter.api.BeforeEach;
|
6 | 9 | import org.junit.jupiter.api.Test;
|
7 | 10 | import org.junit.jupiter.api.TestInfo;
|
@@ -32,4 +35,61 @@ void canUseSnapshotNameAnnotationWithSpaces(TestInfo testInfo) {
|
32 | 35 | expect.toMatchSnapshot("Hello World");
|
33 | 36 | snapshotVerifier.validateSnapshots();
|
34 | 37 | }
|
| 38 | + |
| 39 | + @SnapshotName("can't use '=' character in snapshot name") |
| 40 | + @Test |
| 41 | + void cannotUseEqualsInsideSnapshotName(TestInfo testInfo) { |
| 42 | + SnapshotVerifier snapshotVerifier = |
| 43 | + new SnapshotVerifier(new BaseSnapshotConfig(), testInfo.getTestClass().get()); |
| 44 | + Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); |
| 45 | + assertThrows(ReservedWordException.class, () -> expect.toMatchSnapshot("FooBar")); |
| 46 | + } |
| 47 | + |
| 48 | + @SnapshotName("can't use '[' character in snapshot name") |
| 49 | + @Test |
| 50 | + void cannotUseOpeningSquareBracketInsideSnapshotName(TestInfo testInfo) { |
| 51 | + SnapshotVerifier snapshotVerifier = |
| 52 | + new SnapshotVerifier(new BaseSnapshotConfig(), testInfo.getTestClass().get()); |
| 53 | + Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); |
| 54 | + assertThrows(ReservedWordException.class, () -> expect.toMatchSnapshot("FooBar")); |
| 55 | + } |
| 56 | + |
| 57 | + @SnapshotName("can't use ']' character in snapshot name") |
| 58 | + @Test |
| 59 | + void cannotUseClosingSquareBracketInsideSnapshotName(TestInfo testInfo) { |
| 60 | + SnapshotVerifier snapshotVerifier = |
| 61 | + new SnapshotVerifier(new BaseSnapshotConfig(), testInfo.getTestClass().get()); |
| 62 | + Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); |
| 63 | + assertThrows(ReservedWordException.class, () -> expect.toMatchSnapshot("FooBar")); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + void cannotUseEqualsInsideScenarioName(TestInfo testInfo) { |
| 68 | + SnapshotVerifier snapshotVerifier = |
| 69 | + new SnapshotVerifier(new BaseSnapshotConfig(), testInfo.getTestClass().get()); |
| 70 | + Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); |
| 71 | + assertThrows( |
| 72 | + ReservedWordException.class, |
| 73 | + () -> expect.scenario("can't use = symbol in scenario").toMatchSnapshot("FooBar")); |
| 74 | + } |
| 75 | + |
| 76 | + @Test |
| 77 | + void cannotUseOpeningSquareBracketInsideScenarioName(TestInfo testInfo) { |
| 78 | + SnapshotVerifier snapshotVerifier = |
| 79 | + new SnapshotVerifier(new BaseSnapshotConfig(), testInfo.getTestClass().get()); |
| 80 | + Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); |
| 81 | + assertThrows( |
| 82 | + ReservedWordException.class, |
| 83 | + () -> expect.scenario("can't use [ symbol in scenario").toMatchSnapshot("FooBar")); |
| 84 | + } |
| 85 | + |
| 86 | + @Test |
| 87 | + void cannotUseClosingSquareBracketInsideScenarioName(TestInfo testInfo) { |
| 88 | + SnapshotVerifier snapshotVerifier = |
| 89 | + new SnapshotVerifier(new BaseSnapshotConfig(), testInfo.getTestClass().get()); |
| 90 | + Expect expect = Expect.of(snapshotVerifier, testInfo.getTestMethod().get()); |
| 91 | + assertThrows( |
| 92 | + ReservedWordException.class, |
| 93 | + () -> expect.scenario("can't use ] symbol in scenario").toMatchSnapshot("FooBar")); |
| 94 | + } |
35 | 95 | }
|
0 commit comments