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 { 044 DefaultRepositoryEventDispatcher dispatcher = new DefaultRepositoryEventDispatcher(); 045 046 ListenerHandler handler = new ListenerHandler(); 047 048 RepositoryListener listener = 049 (RepositoryListener) Proxy.newProxyInstance( getClass().getClassLoader(), 050 new Class<?>[] { RepositoryListener.class }, handler ); 051 052 DefaultRepositorySystemSession session = TestUtils.newSession(); 053 session.setRepositoryListener( listener ); 054 055 for ( RepositoryEvent.EventType type : RepositoryEvent.EventType.values() ) 056 { 057 RepositoryEvent event = new RepositoryEvent.Builder( session, type ).build(); 058 059 handler.methodName = null; 060 061 dispatcher.dispatch( event ); 062 063 assertNotNull( "not handled: " + type, handler.methodName ); 064 065 assertEquals( "badly handled: " + type, type.name().replace( "_", "" ).toLowerCase( Locale.ENGLISH ), 066 handler.methodName.toLowerCase( Locale.ENGLISH ) ); 067 } 068 } 069 070 static class ListenerHandler 071 implements InvocationHandler 072 { 073 074 public String methodName; 075 076 public Object invoke( Object proxy, Method method, Object[] args ) 077 { 078 if ( args.length == 1 && args[0] instanceof RepositoryEvent ) 079 { 080 methodName = method.getName(); 081 } 082 083 return null; 084 } 085 086 } 087 088}