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 {
44 DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher();
45
46 ListenerHandler handler = new ListenerHandler();
47
48 RepositoryListener listener =
49 (RepositoryListener) Proxy.newProxyInstance( getClass().getClassLoader(),
50 new Class<?>[] { RepositoryListener.class }, handler );
51
52 DefaultRepositorySystemSession session = TestUtils.newSession();
53 session.setRepositoryListener( listener );
54
55 for ( RepositoryEvent.EventType type : RepositoryEvent.EventType.values() )
56 {
57 RepositoryEvent event = new RepositoryEvent.Builder( session, type ).build();
58
59 handler.methodName = null;
60
61 dispatcher.dispatch( event );
62
63 assertNotNull( "not handled: " + type, handler.methodName );
64
65 assertEquals( "badly handled: " + type, type.name().replace( "_", "" ).toLowerCase( Locale.ENGLISH ),
66 handler.methodName.toLowerCase( Locale.ENGLISH ) );
67 }
68 }
69
70 static class ListenerHandler
71 implements InvocationHandler
72 {
73
74 public String methodName;
75
76 public Object invoke( Object proxy, Method method, Object[] args )
77 {
78 if ( args.length == 1 && args[0] instanceof RepositoryEvent )
79 {
80 methodName = method.getName();
81 }
82
83 return null;
84 }
85
86 }
87
88 }