forked from JavaOPs/topjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestMatcher.java
More file actions
29 lines (21 loc) · 913 Bytes
/
Copy pathTestMatcher.java
File metadata and controls
29 lines (21 loc) · 913 Bytes
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
package ru.javawebinar.topjava;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestMatcher<T> {
private final String[] fieldsToIgnore;
private TestMatcher(String... fieldsToIgnore) {
this.fieldsToIgnore = fieldsToIgnore;
}
public static <T> TestMatcher<T> usingIgnoringFieldsComparator(String... fieldsToIgnore) {
return new TestMatcher<>(fieldsToIgnore);
}
public void assertMatch(T actual, T expected) {
assertThat(actual).usingRecursiveComparison().ignoringFields(fieldsToIgnore).isEqualTo(expected);
}
public void assertMatch(Iterable<T> actual, T... expected) {
assertMatch(actual, List.of(expected));
}
public void assertMatch(Iterable<T> actual, Iterable<T> expected) {
assertThat(actual).usingElementComparatorIgnoringFields(fieldsToIgnore).isEqualTo(expected);
}
}