-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathQueueTest.java
More file actions
38 lines (32 loc) · 1.45 KB
/
Copy pathQueueTest.java
File metadata and controls
38 lines (32 loc) · 1.45 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
import java.net.MalformedURLException;
import java.util.Arrays;
/**
* @author Georgiy Korneev (kgeorgiy@kgeorgiy.info)
*/
public class QueueTest<T extends ArrayQueueTest.Queue> extends ArrayQueueTest<T> {
public static void main(final String[] args) throws MalformedURLException, ClassNotFoundException, NoSuchMethodException {
new QueueTest<>().test();
}
public void test() throws NoSuchMethodException, MalformedURLException, ClassNotFoundException {
test("LinkedQueue", 2, Mode.CLASS);
test("ArrayQueue", 2, Mode.CLASS);
}
@Override
protected T create(final String className, final Mode mode) throws NoSuchMethodException, ClassNotFoundException, MalformedURLException {
return check(super.create(className, mode));
}
protected T check(final T t) {
final Class<?> clazz = t.instance.getClass();
assertTrue(clazz + " should extend AbstractQueue", "AbstractQueue".equals(clazz.getSuperclass().getName()));
assertTrue(clazz + " should implement interface Queue", implementsQueue(clazz) || implementsQueue(clazz.getSuperclass()));
return t;
}
private boolean implementsQueue(final Class<?> clazz) {
return Arrays.stream(clazz.getInterfaces()).anyMatch(iface -> "Queue".equals(iface.getName()));
}
private void assertTrue(final String message, final boolean equals) {
if (!equals) {
throw new AssertionError(message);
}
}
}