-
Notifications
You must be signed in to change notification settings - Fork 6
/
QueueTest.java
37 lines (30 loc) · 1.17 KB
/
QueueTest.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
package queue;
import java.util.Arrays;
/**
* @author Georgiy Korneev ([email protected])
*/
public class QueueTest<T extends ArrayQueueTest.Queue> extends ArrayQueueTest<T> {
public QueueTest(final QueueFactory<T> factory) {
super(factory);
}
public static void main(final String[] args) {
new QueueTest<>(Queue::new).test();
}
public void test() {
test("LinkedQueue", 2, Mode.CLASS);
test("ArrayQueue", 2, Mode.CLASS);
}
@Override
protected T create(final String className, final Mode mode) {
return check(super.create(className, mode));
}
protected static <T extends Queue> T check(final T queue) {
final Class<?> type = queue.instance.getClass();
assertTrue(type + " should extend AbstractQueue", "AbstractQueue".equals(type.getSuperclass().getName()));
assertTrue(type + " should implement interface Queue", implementsQueue(type) || implementsQueue(type.getSuperclass()));
return queue;
}
private static boolean implementsQueue(final Class<?> clazz) {
return Arrays.stream(clazz.getInterfaces()).anyMatch(iface -> "Queue".equals(iface.getName()));
}
}