forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModelsSerializableTest.java
More file actions
63 lines (54 loc) · 2.42 KB
/
Copy pathModelsSerializableTest.java
File metadata and controls
63 lines (54 loc) · 2.42 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
package com.github.dockerjava.api;
import com.github.dockerjava.api.model.Binds;
import com.github.dockerjava.api.model.BuildResponseItem;
import com.github.dockerjava.api.model.PullResponseItem;
import com.github.dockerjava.api.model.PushResponseItem;
import com.github.dockerjava.api.model.ResponseItem;
import com.google.common.reflect.ClassPath.ClassInfo;
import org.apache.commons.lang.reflect.FieldUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import static com.google.common.reflect.ClassPath.from;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.object.IsCompatibleType.typeCompatibleWith;
import static org.junit.Assert.assertThat;
/**
* @author Kanstantsin Shautsou
*/
public class ModelsSerializableTest {
private static final Logger LOG = LoggerFactory.getLogger(ModelsSerializableTest.class);
private List<String> excludeClasses = Arrays.asList(
Binds.class.getName(),
BuildResponseItem.class.getName(),
PullResponseItem.class.getName(),
PushResponseItem.class.getName(),
ResponseItem.class.getName()
);
@Test
public void allModelsSerializable() throws IOException, NoSuchFieldException, IllegalAccessException {
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
for (ClassInfo classInfo : from(contextClassLoader).getTopLevelClasses("com.github.dockerjava.api.model")) {
if (classInfo.getName().endsWith("Test")) {
continue;
}
final Class<?> aClass = classInfo.load();
if (aClass.getProtectionDomain().getCodeSource().getLocation().getPath().endsWith("test-classes/")
|| aClass.isEnum()) {
continue;
}
LOG.debug("aClass: {}", aClass);
assertThat(aClass, typeCompatibleWith(Serializable.class));
final Object serialVersionUID = FieldUtils.readDeclaredStaticField(aClass, "serialVersionUID", true);
if (!excludeClasses.contains(aClass.getName())) {
assertThat(serialVersionUID, instanceOf(Long.class));
assertThat("Follow devel docs", (Long) serialVersionUID, is(1L));
}
}
}
}