1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.aether.internal.impl;
20
21 import java.lang.reflect.InvocationHandler;
22 import java.lang.reflect.Method;
23 import java.lang.reflect.Proxy;
24 import java.util.Locale;
25
26 import org.eclipse.aether.DefaultRepositorySystemSession;
27 import org.eclipse.aether.RepositoryEvent;
28 import org.eclipse.aether.RepositoryListener;
29 import org.eclipse.aether.internal.test.util.TestUtils;
30 import org.junit.Test;
31
32 import static org.junit.Assert.*;
33
34
35
36 public class DefaultRepositoryEventDispatcherTest {
37
38 @Test
39 public void testDispatchHandlesAllEventTypes() {
40 DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher();
41
42 ListenerHandler handler = new ListenerHandler();
43
44 RepositoryListener listener = (RepositoryListener)
45 Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] {RepositoryListener.class}, handler);
46
47 DefaultRepositorySystemSession session = TestUtils.newSession();
48 session.setRepositoryListener(listener);
49
50 for (RepositoryEvent.EventType type : RepositoryEvent.EventType.values()) {
51 RepositoryEvent event = new RepositoryEvent.Builder(session, type).build();
52
53 handler.methodName = null;
54
55 dispatcher.dispatch(event);
56
57 assertNotNull("not handled: " + type, handler.methodName);
58
59 assertEquals(
60 "badly handled: " + type,
61 type.name().replace("_", "").toLowerCase(Locale.ENGLISH),
62 handler.methodName.toLowerCase(Locale.ENGLISH));
63 }
64 }
65
66 static class ListenerHandler implements InvocationHandler {
67
68 public String methodName;
69
70 public Object invoke(Object proxy, Method method, Object[] args) {
71 if (args.length == 1 && args[0] instanceof RepositoryEvent) {
72 methodName = method.getName();
73 }
74
75 return null;
76 }
77 }
78 }