Skip to content

Commit 03aacbf

Browse files
committed
Functional test validator refactor to reduce redundant code
1 parent b664555 commit 03aacbf

25 files changed

Lines changed: 671 additions & 1140 deletions

src/main/java/com/amilesend/tmdb/client/connection/auth/TokenAuthInfo.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* tmdb-java-client - A client to access the TMDB API
3+
* Copyright © 2024-2025 Andy Miles (andy.miles@amilesend.com)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
118
package com.amilesend.tmdb.client.connection.auth;
219

320
import com.amilesend.client.connection.auth.AuthInfo;

src/main/java/com/amilesend/tmdb/client/connection/auth/TokenAuthManager.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* tmdb-java-client - A client to access the TMDB API
3+
* Copyright © 2024-2025 Andy Miles (andy.miles@amilesend.com)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
118
package com.amilesend.tmdb.client.connection.auth;
219

320
import com.amilesend.client.connection.auth.AuthManager;
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* tmdb-java-client - A client to access the TMDB API
3+
* Copyright © 2024-2025 Andy Miles (andy.miles@amilesend.com)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.amilesend.tmdb.client.data;
19+
20+
import com.amilesend.tmdb.client.model.NamedResource;
21+
import com.amilesend.tmdb.client.model.Resource;
22+
import lombok.experimental.UtilityClass;
23+
24+
import java.util.List;
25+
import java.util.Objects;
26+
27+
import static org.junit.jupiter.api.Assertions.assertAll;
28+
import static org.junit.jupiter.api.Assertions.assertEquals;
29+
import static org.junit.jupiter.api.Assertions.assertNotNull;
30+
import static org.junit.jupiter.api.Assertions.assertNull;
31+
import static org.junit.jupiter.api.Assertions.assertTrue;
32+
33+
@UtilityClass
34+
public class DataValidatorHelper {
35+
public static void validateResource(final Resource expected, final Resource actual) {
36+
if (Objects.isNull(expected)) {
37+
assertNull(actual);
38+
return;
39+
}
40+
41+
assertEquals(expected.getId(), actual.getId());
42+
}
43+
44+
public static void validateNamedResource(final NamedResource expected, final NamedResource actual) {
45+
if (Objects.isNull(expected)) {
46+
assertNull(actual);
47+
return;
48+
}
49+
50+
assertAll(
51+
() -> validateResource(expected, actual),
52+
() -> assertEquals(expected.getName(), actual.getName()));
53+
}
54+
55+
public static <T> void validateListOf(
56+
final List<T> expected,
57+
final List<T> actual,
58+
final ItemValidator<T> itemValidator) {
59+
if (Objects.isNull(expected)) {
60+
assertNull(actual);
61+
return;
62+
}
63+
64+
assertNotNull(actual);
65+
66+
if (expected.isEmpty()) {
67+
assertTrue(actual.isEmpty());
68+
return;
69+
}
70+
71+
assertEquals(expected.size(), actual.size());
72+
73+
for (int i = 0; i < expected.size(); ++i) {
74+
itemValidator.validate(expected.get(i), actual.get(i));
75+
}
76+
}
77+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* tmdb-java-client - A client to access the TMDB API
3+
* Copyright © 2024-2025 Andy Miles (andy.miles@amilesend.com)
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.amilesend.tmdb.client.data;
19+
20+
@FunctionalInterface
21+
public interface ItemValidator<T> {
22+
void validate(T expected, T actual);
23+
}

0 commit comments

Comments
 (0)