Skip to content

Commit

Permalink
. d updated markdown snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 26, 2024
1 parent 28ec2f4 commit 0a9bb4a
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 28 deletions.
8 changes: 4 additions & 4 deletions approvaltests-util/docs/ArrayUtils.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
ArrayUtils has the ability to dynamically determine the type of your list.

<!-- snippet: toArray -->
<a id='snippet-toarray'></a>
<a id='snippet-toArray'></a>
```java
List<Comparable> comparables = new ArrayList<>();
comparables.add(null);
Expand All @@ -21,18 +21,18 @@ comparables.add(3.1415);
comparables.add("Lars");
Comparable[] comparableArray = ArrayUtils.toArray(comparables);
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/ArrayUtilsTest.java#L101-L108' title='Snippet source file'>snippet source</a> | <a href='#snippet-toarray' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/ArrayUtilsTest.java#L101-L108' title='Snippet source file'>snippet source</a> | <a href='#snippet-toArray' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

This works in almost all cases with the notable exceptions of empty arrays, some common interfaces
which will not be preferenced.
In which case you can always use the overloaded method
<!-- snippet: toArrayWithClass -->
<a id='snippet-toarraywithclass'></a>
<a id='snippet-toArrayWithClass'></a>
```java
Comparable[] array = ArrayUtils.toArray(comparables, Comparable.class);
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/ArrayUtilsTest.java#L109-L111' title='Snippet source file'>snippet source</a> | <a href='#snippet-toarraywithclass' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/ArrayUtilsTest.java#L109-L111' title='Snippet source file'>snippet source</a> | <a href='#snippet-toArrayWithClass' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->


Expand Down
12 changes: 6 additions & 6 deletions approvaltests-util/docs/how_to/VarArgsWithAtleastOne.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ Most solutions for this occur at runtime. Of course, it would be better if they
### Runtime solution

<!-- snippet: minimalVarargsRuntime -->
<a id='snippet-minimalvarargsruntime'></a>
<a id='snippet-minimalVarargsRuntime'></a>
```java
public Integer findSmallest(Integer... numbers)
{
if (numbers == null || numbers.length < 1)
{ throw new IllegalArgumentException("you must have at least one number"); }
// rest of the code
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/MinimumVarargSamples.java#L20-L26' title='Snippet source file'>snippet source</a> | <a href='#snippet-minimalvarargsruntime' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/MinimumVarargSamples.java#L20-L26' title='Snippet source file'>snippet source</a> | <a href='#snippet-minimalVarargsRuntime' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Compile time solution
Expand All @@ -37,14 +37,14 @@ If you do this, you will want to recombine this array almost immediately `ArrayU
Please be aware that it will not work with primitives.

<!-- snippet: minimalVarargsCompileTime -->
<a id='snippet-minimalvarargscompiletime'></a>
<a id='snippet-minimalVarargsCompileTime'></a>
```java
public Integer findSmallest(Integer first, Integer... numbers)
{
Integer[] combined = ArrayUtils.combine(first, numbers);
// rest of the code
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/MinimumVarargSamples.java#L29-L34' title='Snippet source file'>snippet source</a> | <a href='#snippet-minimalvarargscompiletime' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/MinimumVarargSamples.java#L29-L34' title='Snippet source file'>snippet source</a> | <a href='#snippet-minimalVarargsCompileTime' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Advantages
Expand All @@ -53,11 +53,11 @@ If you use the runtime solution, the following will compile but throw an error w
If you use the compile time solution, it will not compile.

<!-- snippet: minimalVarargsException -->
<a id='snippet-minimalvarargsexception'></a>
<a id='snippet-minimalVarargsException'></a>
```java
int smallest = findSmallest();
```
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/MinimumVarargSamples.java#L12-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-minimalvarargsexception' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-util-tests/src/test/java/com/spun/util/MinimumVarargSamples.java#L12-L14' title='Snippet source file'>snippet source</a> | <a href='#snippet-minimalVarargsException' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

### Where to use this
Expand Down
4 changes: 2 additions & 2 deletions approvaltests/docs/Scrubbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ created at [Date1]
If you need to do scrubbing of multiple things, the easiest way is to create multiple scrubbers and then combine them.

<!-- snippet: MultiScrubber -->
<a id='snippet-multiscrubber'></a>
<a id='snippet-MultiScrubber'></a>
```java
final Scrubber portScrubber = new RegExScrubber(":\\d+/", ":[port]/");
final Scrubber dateScrubber = DateScrubber.getScrubberFor("20210505T091112Z");
Expand All @@ -156,7 +156,7 @@ Scrubber scrubber = Scrubbers.scrubAll(portScrubber, dateScrubber, signatureScru
Approvals.verify("http://127.0.0.1:55079/foo/bar?Date=20210505T091112Z&Signature=4a7dd6f09c1e",
new Options(scrubber));
```
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/ScrubberTest.java#L47-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-multiscrubber' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/scrubbers/ScrubberTest.java#L47-L54' title='Snippet source file'>snippet source</a> | <a href='#snippet-MultiScrubber' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

will result in
Expand Down
4 changes: 2 additions & 2 deletions approvaltests/docs/how_to/MachineNameSpecificTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ It checks if the current machine's name matches the specified name (e.g., ".lars
The actual test code should be placed after this condition.

<!-- snippet: runOnlyOnSpecificMachines -->
<a id='snippet-runonlyonspecificmachines'></a>
<a id='snippet-runOnlyOnSpecificMachines'></a>
```java
try (NamedEnvironment namedEnvironment = NamerFactory.asMachineNameSpecificTest())
{
if (!namedEnvironment.isCurrentEnvironmentValidFor(".lars-mbp-14"))
{ return; }
// the rest of your test...
```
<sup><a href='/approvaltests/src/test/java/org/approvaltests/reporters/intellij/IntelliJPathResolverTest.java#L60-L66' title='Snippet source file'>snippet source</a> | <a href='#snippet-runonlyonspecificmachines' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests/src/test/java/org/approvaltests/reporters/intellij/IntelliJPathResolverTest.java#L60-L66' title='Snippet source file'>snippet source</a> | <a href='#snippet-runOnlyOnSpecificMachines' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

**please note:** this will also append the machine name to the ApprovalTest so that each specific
Expand Down
4 changes: 2 additions & 2 deletions approvaltests/docs/how_to/ShowNullsInJson.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ To modify this behavior and display null fields,
follow the example provided below.

<!-- snippet: CustomGsonBuilderShowingNull -->
<a id='snippet-customgsonbuildershowingnull'></a>
<a id='snippet-CustomGsonBuilderShowingNull'></a>
```java
Person person = new Person("Max", null, 1);
JsonApprovals.verifyAsJson(person, GsonBuilder::serializeNulls);
```
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/JsonFormattingTest.java#L33-L36' title='Snippet source file'>snippet source</a> | <a href='#snippet-customgsonbuildershowingnull' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/JsonFormattingTest.java#L33-L36' title='Snippet source file'>snippet source</a> | <a href='#snippet-CustomGsonBuilderShowingNull' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
4 changes: 2 additions & 2 deletions approvaltests/docs/how_to/TestAVarietyOfValues.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ If you have more than one parameter that you want to vary, check out [Testing Co
1. Copy this starter text.

<!-- snippet: VerifyAllStartingPoint -->
<a id='snippet-verifyallstartingpoint'></a>
<a id='snippet-VerifyAllStartingPoint'></a>
```java
String[] inputs = {"input.value1", "input.value2"};
Approvals.verifyAll("TITLE", inputs, s -> "placeholder " + s);
```
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/ApprovalsTest.java#L46-L49' title='Snippet source file'>snippet source</a> | <a href='#snippet-verifyallstartingpoint' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/ApprovalsTest.java#L46-L49' title='Snippet source file'>snippet source</a> | <a href='#snippet-VerifyAllStartingPoint' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

2. Modify the input container for your chosen values.
Expand Down
8 changes: 4 additions & 4 deletions approvaltests/docs/how_to/TestCombinations.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ If you have only one parameter that you want to vary, check out [How to Test a V
1. Copy this starter text, and adjust for the number of inputs that you have.

<!-- snippet: CombinationsStartingPoint -->
<a id='snippet-combinationsstartingpoint'></a>
<a id='snippet-CombinationsStartingPoint'></a>
```java
String[] inputs1 = {"input1.value1", "input1.value2"};
String[] inputs2 = {"input2.value1", "input2.value2", "input2.value3"};
CombinationApprovals.verifyAllCombinations((a, b) -> "placeholder", inputs1, inputs2);
```
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/combinations/CombinationTest.java#L42-L46' title='Snippet source file'>snippet source</a> | <a href='#snippet-combinationsstartingpoint' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/combinations/CombinationTest.java#L42-L46' title='Snippet source file'>snippet source</a> | <a href='#snippet-CombinationsStartingPoint' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

2. Modify each input container for your chosen values.
Expand Down Expand Up @@ -60,13 +60,13 @@ This makes a kind of approval test matrix, automatically testing all combination
In this small example, all combinations of `{"hello", "world"}` and `{1, 2, 3}` are being used:

<!-- snippet: YouCanVerifyCombinationsOf2 -->
<a id='snippet-youcanverifycombinationsof2'></a>
<a id='snippet-YouCanVerifyCombinationsOf2'></a>
```java
String[] strings = {"hello", "world"};
Integer[] numbers = {1, 2, 3};
CombinationApprovals.verifyAllCombinations((s, i) -> String.format("(%s,%s)", s, i), strings, numbers);
```
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/combinations/CombinationTest.java#L51-L55' title='Snippet source file'>snippet source</a> | <a href='#snippet-youcanverifycombinationsof2' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/combinations/CombinationTest.java#L51-L55' title='Snippet source file'>snippet source</a> | <a href='#snippet-YouCanVerifyCombinationsOf2' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

The format is carefully chosen to show both inputs and outputs, to make the test results easy to interpret. The output looks like this:
Expand Down
4 changes: 2 additions & 2 deletions approvaltests/docs/reference/AwtApprovals.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ To create such a gif you pass the number of frames you want plus a function that
for every frame. Here is an example for a simple expanding box:

<!-- snippet: SequencePaintables -->
<a id='snippet-sequencepaintables'></a>
<a id='snippet-SequencePaintables'></a>
```java
SquareDrawer squareDrawer = new SquareDrawer();
AwtApprovals.verifySequence(5, f -> squareDrawer.setSquareSize(f * 10));
```
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/awt/ApprovalsTest.java#L48-L51' title='Snippet source file'>snippet source</a> | <a href='#snippet-sequencepaintables' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/awt/ApprovalsTest.java#L48-L51' title='Snippet source file'>snippet source</a> | <a href='#snippet-SequencePaintables' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

**Note**: Method overloads allow specifying the time between frames or the time for each frame.
Expand Down
4 changes: 2 additions & 2 deletions approvaltests/docs/reference/IntelliJReporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ This page exists when IntelliJ is not being found in your system.
Currently, here are some of the paths that are supported:

<!-- snippet: SupportedIntelliJPaths -->
<a id='snippet-supportedintellijpaths'></a>
<a id='snippet-SupportedIntelliJPaths'></a>
```java
"/Users/fakeUser/Library/Application Support/JetBrains/Toolbox/apps/IDEA-C/ch-0/223.8617.56/IntelliJ IDEA CE.app/Contents/MacOS/idea",
"/Users/fakeUser/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/223.8617.56/IntelliJ IDEA 2022.2 EAP.app"
```
<sup><a href='/approvaltests/src/test/java/org/approvaltests/reporters/intellij/IntelliJPathResolverTest.java#L79-L82' title='Snippet source file'>snippet source</a> | <a href='#snippet-supportedintellijpaths' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests/src/test/java/org/approvaltests/reporters/intellij/IntelliJPathResolverTest.java#L79-L82' title='Snippet source file'>snippet source</a> | <a href='#snippet-SupportedIntelliJPaths' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

If IntelliJ is not opening for you,
4 changes: 2 additions & 2 deletions approvaltests/docs/reference/StoryBoard.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ StoryBoards can be very helpful to tell a story of steps that happen over time.
Here is a simple example

<!-- snippet: StoryBoardExample -->
<a id='snippet-storyboardexample'></a>
<a id='snippet-StoryBoardExample'></a>
```java
Approvals.verify(new StoryBoard().add(gameOfLife).addFrames(3, gameOfLife::advance));
```
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/StoryBoardTest.java#L23-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-storyboardexample' title='Start of snippet'>anchor</a></sup>
<sup><a href='/approvaltests-tests/src/test/java/org/approvaltests/StoryBoardTest.java#L23-L25' title='Snippet source file'>snippet source</a> | <a href='#snippet-StoryBoardExample' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

which produces
Expand Down

0 comments on commit 0a9bb4a

Please sign in to comment.