-
Notifications
You must be signed in to change notification settings - Fork 74
/
Copy pathApprovalsTest.java
88 lines (85 loc) · 2.81 KB
/
ApprovalsTest.java
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package org.approvaltests.awt;
import com.spun.util.Tuple;
import org.approvaltests.Approvals;
import org.approvaltests.core.Options;
import org.approvaltests.reporters.FileCaptureReporter;
import org.approvaltests.reporters.ImageWebReporter;
import org.approvaltests.reporters.UseReporter;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnJre;
import org.junit.jupiter.api.condition.EnabledOnJre;
import org.junit.jupiter.api.condition.JRE;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.time.Duration;
//@UseReporter({FileCaptureReporter.class})
public class ApprovalsTest
{
@BeforeAll
static void beforeAll()
{
Approvals.settings().allowMultipleVerifyCallsForThisClass();
}
@Test
void customPanel()
{
CustomPanel panel = new CustomPanel();
AwtApprovals.verify(panel);
}
@Disabled("continue here next week")
@Test
void customPanelWithText()
{
// begin-snippet: file_capture_reporter_example
CustomPanel panel = new CustomPanel(true, 20);
AwtApprovals.verify(panel, new Options(new FileCaptureReporter()));
// end-snippet
}
@Test
@UseReporter(ImageWebReporter.class)
void testSequence()
{
// begin-snippet: SequencePaintables
SquareDrawer squareDrawer = new SquareDrawer();
AwtApprovals.verifySequence(5, f -> squareDrawer.setSquareSize(f * 10));
// end-snippet
AwtApprovals.verifySequence(5, Duration.ofMillis(500), f1 -> squareDrawer.setSquareSize(f1 * 10));
}
@Test
@UseReporter(ImageWebReporter.class)
void testSequenceWithInitialState()
{
SquareDrawer squareDrawer = new SquareDrawer();
squareDrawer.setSquareSize(80);
AwtApprovals.verifySequence(squareDrawer, 4, f -> squareDrawer.setSquareSize(f * 10 + 1));
squareDrawer.setSquareSize(80);
AwtApprovals.verifySequence(squareDrawer, 4, Duration.ofMillis(500),
f1 -> squareDrawer.setSquareSize(f1 * 10 + 1));
}
@Test
@UseReporter(ImageWebReporter.class)
void testSequenceWithTimings()
{
SquareDrawer squareDrawer = new SquareDrawer();
AwtApprovals.verifySequenceWithTimings(5,
f -> new Tuple<>(squareDrawer.setSquareSize(f * 10), Duration.ofSeconds(1 + f)));
}
@Test
@UseReporter(FileCaptureReporter.class)
void testBufferedImage()
{
BufferedImage bufferedImage = new BufferedImage(60, 30, BufferedImage.TYPE_INT_ARGB);
Graphics graphics = bufferedImage.getGraphics();
graphics.setColor(Color.BLUE);
graphics.fillRect(0, 0, 60, 10);
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 10, 60, 10);
graphics.setColor(Color.WHITE);
graphics.fillRect(0, 20, 60, 10);
AwtApprovals.verify(bufferedImage);
AwtApprovals.verify(bufferedImage, new Options());
}
}