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