-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathApprovalsTest.java
More file actions
69 lines (60 loc) · 1.74 KB
/
ApprovalsTest.java
File metadata and controls
69 lines (60 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.approvaltests;
import com.spun.util.io.FileUtils;
import org.approvaltests.core.Options;
import org.approvaltests.reporters.*;
import org.approvaltests.reporters.ReportWithBeyondCompare;
import org.junit.jupiter.api.Test;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.io.File;
import java.io.StringReader;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertThrows;
@UseReporter({DiffReporter.class, ClipboardReporter.class})
public class ApprovalsTest
{
@Test
public void testToString()
{
Rectangle objectUnderTest = new Rectangle(5, 10, 100, 200);
// begin-snippet: configure_reporter_with_options
Options options = new Options().withReporter(ReportWithBeyondCompare.INSTANCE);
Approvals.verify(objectUnderTest, options);
// end-snippet
}
@Test
public void testAsJson()
{
JsonApprovals.verifyAsJson(new Rectangle(5, 10, 100, 200));
}
@Test
public void testWrongCall()
{
Approvals.verifyException(() -> {
JButton b = new JButton("Approval Tests Rule");
b.setPreferredSize(new Dimension(150, 20));
Approvals.verify(b, new Options(new ReportNothing()));
});
}
@Test
void verifyAllTemplate()
{
// begin-snippet: VerifyAllStartingPoint
String[] inputs = {"input.value1", "input.value2"};
Approvals.verifyAll("TITLE", inputs, s -> "placeholder " + s);
// end-snippet
}
@Test
void testTwoVerify()
{
Approvals.verify("one");
assertThrows(ApprovalsDuplicateVerifyException.class, () -> Approvals.verify("two"));
}
@Test
void verifyPath()
{
File file = FileUtils.saveToFile("pre_", ".txt", new StringReader("hello from Path"));
Approvals.verify(file.toPath());
}
}