001package org.eclipse.aether.internal.impl; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.junit.Assert.*; 023 024import java.lang.reflect.InvocationHandler; 025import java.lang.reflect.Method; 026import java.lang.reflect.Proxy; 027import java.util.Locale; 028 029import org.eclipse.aether.DefaultRepositorySystemSession; 030import org.eclipse.aether.RepositoryEvent; 031import org.eclipse.aether.RepositoryListener; 032import org.eclipse.aether.internal.impl.DefaultRepositoryEventDispatcher; 033import org.eclipse.aether.internal.test.util.TestUtils; 034import org.junit.Test; 035 036/** 037 */ 038public class DefaultRepositoryEventDispatcherTest 039{ 040 041 @Test 042 public void testDispatchHandlesAllEventTypes() 043 throws Exception 044 { 045 DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher(); 046 047 ListenerHandler handler = new ListenerHandler(); 048 049 RepositoryListener listener = 050 (RepositoryListener) Proxy.newProxyInstance( getClass().getClassLoader(), 051 new Class<?>[] { RepositoryListener.class }, handler ); 052 053 DefaultRepositorySystemSession session = TestUtils.newSession(); 054 session.setRepositoryListener( listener ); 055 056 for ( RepositoryEvent.EventType type : RepositoryEvent.EventType.values() ) 057 { 058 RepositoryEvent event = new RepositoryEvent.Builder( session, type ).build(); 059 060 handler.methodName = null; 061 062 dispatcher.dispatch( event ); 063 064 assertNotNull( "not handled: " + type, handler.methodName ); 065 066 assertEquals( "badly handled: " + type, type.name().replace( "_", "" ).toLowerCase( Locale.ENGLISH ), 067 handler.methodName.toLowerCase( Locale.ENGLISH ) ); 068 } 069 } 070 071 static class ListenerHandler 072 implements InvocationHandler 073 { 074 075 public String methodName; 076 077 public Object invoke( Object proxy, Method method, Object[] args ) 078 throws Throwable 079 { 080 if ( args.length == 1 && args[0] instanceof RepositoryEvent ) 081 { 082 methodName = method.getName(); 083 } 084 085 return null; 086 } 087 088 } 089 090}