// Path: src/main/java/com/antelink/sourcesquare/event/base/EventBus.java
// public class EventBus {
// 
//     private static final Log logger = LogFactory.getLog(EventBus.class);
// 
//     HashMap<ClientEventType<?>, List<? extends ClientEventHandler>> eventMap = new HashMap<ClientEventType<?>, List<? extends ClientEventHandler>>();
// 
//     @SuppressWarnings("unchecked")
//     public <T extends ClientEventHandler> void addHandler(ClientEventType<T> eventType, T handler) {
//         if (!this.eventMap.containsKey(eventType)) {
//             this.eventMap.put(eventType, new ArrayList<T>());
//         }
//         ((ArrayList<T>) this.eventMap.get(eventType)).add(0, handler);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public <T extends ClientEventHandler> void fireEvent(final ClientEvent<T> event) {
//         if (!this.eventMap.containsKey(event.getHandlerType())) {
//             return;
//         }
//         for (final ClientEventHandler handler : this.eventMap.get(event.getHandlerType())) {
//             try {
//                 Runnable runner = new Runnable() {
// 
//                     @Override
//                     public void run() { 
//                         event.dispatch((T) handler);
// 
//                     }
//                 };
// 
//                 Thread thread = new Thread(runner);
//                 thread.start();
// 
//                 logger.trace("event dispatched to the handler " + handler.getId());
//             } catch (Exception e) {
//                 logger.error("An event could not be dispatched to the handler " + handler.getId(), e);
//             }
//         }
//     }
// }
// 
// Path: src/main/java/com/antelink/sourcesquare/event/events/FilesIdentifiedEvent.java
// public class FilesIdentifiedEvent implements ClientEvent<FilesIdentifiedEventHandler> {
// 
//     public static final ClientEventType<FilesIdentifiedEventHandler> TYPE = new ClientEventType<FilesIdentifiedEventHandler>();
// 
//     private final TreeSet<File> fileSet;
// 
//     public FilesIdentifiedEvent(TreeSet<File> fileSet) {
//         this.fileSet = fileSet;
//     }
// 
//     @Override
//     public ClientEventType<FilesIdentifiedEventHandler> getHandlerType() {
//         return TYPE;
//     }
// 
//     @Override
//     public void dispatch(FilesIdentifiedEventHandler handler) {
//         handler.handle(this.fileSet);
// 
//     }
// 
//     public TreeSet<File> getFileSet() {
//         return this.fileSet;
//     }
// 
// }
// 
// Path: src/main/java/com/antelink/sourcesquare/event/events/OSFilesFoundEvent.java
// public class OSFilesFoundEvent implements ClientEvent<OSFilesFoundEventHandler> {
// 
//     public static final ClientEventType<OSFilesFoundEventHandler> TYPE = new ClientEventType<OSFilesFoundEventHandler>();
// 
//     private final Set<String> fileSet;
// 
//     public OSFilesFoundEvent(Set<String> fileSet) {
//         this.fileSet = fileSet;
//     }
// 
//     @Override
//     public ClientEventType<OSFilesFoundEventHandler> getHandlerType() {
//         return TYPE;
//     }
// 
//     @Override
//     public void dispatch(OSFilesFoundEventHandler handler) {
//         handler.handle(this.fileSet);
//     }
// 
//     public Set<String> getFileSet() {
//         return this.fileSet;
//     }
// 
// }


import org.easymock.EasyMock;
import org.easymock.IAnswer;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import com.antelink.sourcesquare.event.base.EventBus;
import com.antelink.sourcesquare.event.events.FilesIdentifiedEvent;
import com.antelink.sourcesquare.event.events.OSFilesFoundEvent;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
/**
 * Copyright (C) 2009-2012 Antelink SAS
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License Version 3 as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License Version 3
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License Version
 * 3 along with this program. If not, see http://www.gnu.org/licenses/agpl.html
 *
 * Additional permission under GNU AGPL version 3 section 7
 *
 * If you modify this Program, or any covered work, by linking or combining it with
 * Eclipse Java development tools (JDT) or Jetty (or a modified version of these
 * libraries), containing parts covered by the terms of Eclipse Public License 1.0,
 * the licensors of this Program grant you additional permission to convey the
 * resulting work. Corresponding Source for a non-source form of such a combination
 * shall include the source code for the parts of Eclipse Java development tools
 * (JDT) or Jetty used as well as that of the covered work.
 */
package com.antelink.sourcesquare.badge;






public class TestBadgeProcessor {
	
	BadgesProcessor processor;
	EventBus bus;
	Integer count=0;
	
	TreeSet<File> files=new TreeSet<File>(Arrays.asList(new File(""),new File(""),new File(""),new File(""),new File(""),new File(""),new File(""),new File(""),new File(""),new File("")));
	
	
	@Before
	public void init(){
		bus=new EventBus();
		processor=new BadgesProcessor(bus);
		processor.bind();
		count=0;
	}

	@Test @Ignore
	// Ignored test: too asynchronous to be trusted...
	public void testBadgesOpenSourceSamurai(){
		Set<String> set=EasyMock.createMock(Set.class);
		expect(set.size()).andReturn(8).andAnswer(new IAnswer<Integer>() {

			@Override
			public Integer answer() throws Throwable {
				synchronized (count) {
					count++;
				}
				return null;
			}
		});
				
		bus.fireEvent(new OSFilesFoundEvent(set));
// Path: src/main/java/com/antelink/sourcesquare/event/base/EventBus.java
// public class EventBus {
// 
//     private static final Log logger = LogFactory.getLog(EventBus.class);
// 
//     HashMap<ClientEventType<?>, List<? extends ClientEventHandler>> eventMap = new HashMap<ClientEventType<?>, List<? extends ClientEventHandler>>();
// 
//     @SuppressWarnings("unchecked")
//     public <T extends ClientEventHandler> void addHandler(ClientEventType<T> eventType, T handler) {
//         if (!this.eventMap.containsKey(eventType)) {
//             this.eventMap.put(eventType, new ArrayList<T>());
//         }
//         ((ArrayList<T>) this.eventMap.get(eventType)).add(0, handler);
//     }
// 
//     @SuppressWarnings("unchecked")
//     public <T extends ClientEventHandler> void fireEvent(final ClientEvent<T> event) {
//         if (!this.eventMap.containsKey(event.getHandlerType())) {
//             return;
//         }
//         for (final ClientEventHandler handler : this.eventMap.get(event.getHandlerType())) {
//             try {
//                 Runnable runner = new Runnable() {
// 
//                     @Override
//                     public void run() { 
//                         event.dispatch((T) handler);
// 
//                     }
//                 };
// 
//                 Thread thread = new Thread(runner);
//                 thread.start();
// 
//                 logger.trace("event dispatched to the handler " + handler.getId());
//             } catch (Exception e) {
//                 logger.error("An event could not be dispatched to the handler " + handler.getId(), e);
//             }
//         }
//     }
// }
// 
// Path: src/main/java/com/antelink/sourcesquare/event/events/FilesIdentifiedEvent.java
// public class FilesIdentifiedEvent implements ClientEvent<FilesIdentifiedEventHandler> {
// 
//     public static final ClientEventType<FilesIdentifiedEventHandler> TYPE = new ClientEventType<FilesIdentifiedEventHandler>();
// 
//     private final TreeSet<File> fileSet;
// 
//     public FilesIdentifiedEvent(TreeSet<File> fileSet) {
//         this.fileSet = fileSet;
//     }
// 
//     @Override
//     public ClientEventType<FilesIdentifiedEventHandler> getHandlerType() {
//         return TYPE;
//     }
// 
//     @Override
//     public void dispatch(FilesIdentifiedEventHandler handler) {
//         handler.handle(this.fileSet);
// 
//     }
// 
//     public TreeSet<File> getFileSet() {
//         return this.fileSet;
//     }
// 
// }
// 
// Path: src/main/java/com/antelink/sourcesquare/event/events/OSFilesFoundEvent.java
// public class OSFilesFoundEvent implements ClientEvent<OSFilesFoundEventHandler> {
// 
//     public static final ClientEventType<OSFilesFoundEventHandler> TYPE = new ClientEventType<OSFilesFoundEventHandler>();
// 
//     private final Set<String> fileSet;
// 
//     public OSFilesFoundEvent(Set<String> fileSet) {
//         this.fileSet = fileSet;
//     }
// 
//     @Override
//     public ClientEventType<OSFilesFoundEventHandler> getHandlerType() {
//         return TYPE;
//     }
// 
//     @Override
//     public void dispatch(OSFilesFoundEventHandler handler) {
//         handler.handle(this.fileSet);
//     }
// 
//     public Set<String> getFileSet() {
//         return this.fileSet;
//     }
// 
// }


// Path: src/test/java/com/antelink/sourcesquare/badge/TestBadgeProcessor.java
import org.easymock.EasyMock;
import org.easymock.IAnswer;
import static org.easymock.EasyMock.*;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import com.antelink.sourcesquare.event.base.EventBus;
import com.antelink.sourcesquare.event.events.FilesIdentifiedEvent;
import com.antelink.sourcesquare.event.events.OSFilesFoundEvent;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;

/**
 * Copyright (C) 2009-2012 Antelink SAS
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License Version 3 as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License Version 3
 * for more details.
 *
 * You should have received a copy of the GNU Affero General Public License Version
 * 3 along with this program. If not, see http://www.gnu.org/licenses/agpl.html
 *
 * Additional permission under GNU AGPL version 3 section 7
 *
 * If you modify this Program, or any covered work, by linking or combining it with
 * Eclipse Java development tools (JDT) or Jetty (or a modified version of these
 * libraries), containing parts covered by the terms of Eclipse Public License 1.0,
 * the licensors of this Program grant you additional permission to convey the
 * resulting work. Corresponding Source for a non-source form of such a combination
 * shall include the source code for the parts of Eclipse Java development tools
 * (JDT) or Jetty used as well as that of the covered work.
 */
package com.antelink.sourcesquare.badge;






public class TestBadgeProcessor {
	
	BadgesProcessor processor;
	EventBus bus;
	Integer count=0;
	
	TreeSet<File> files=new TreeSet<File>(Arrays.asList(new File(""),new File(""),new File(""),new File(""),new File(""),new File(""),new File(""),new File(""),new File(""),new File("")));
	
	
	@Before
	public void init(){
		bus=new EventBus();
		processor=new BadgesProcessor(bus);
		processor.bind();
		count=0;
	}

	@Test @Ignore
	// Ignored test: too asynchronous to be trusted...
	public void testBadgesOpenSourceSamurai(){
		Set<String> set=EasyMock.createMock(Set.class);
		expect(set.size()).andReturn(8).andAnswer(new IAnswer<Integer>() {

			@Override
			public Integer answer() throws Throwable {
				synchronized (count) {
					count++;
				}
				return null;
			}
		});
				
		bus.fireEvent(new OSFilesFoundEvent(set));
		bus.fireEvent(new FilesIdentifiedEvent(files));