@@ -0,0 +1,2258 @@
+/*%0A * Copyright 2000-2018 JetBrains s.r.o.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage com.turn.ttorrent.client;%0A%0Aimport org.testng.annotations.BeforeMethod;%0Aimport org.testng.annotations.Test;%0A%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.testng.Assert.assertEquals;%0A%0A@Test%0Apublic class EventDispatcherTest %7B%0A%0A  private EventDispatcher eventDispatcher;%0A  private PeerInformation peerInfo;%0A  private PieceInformation pieceInfo;%0A%0A  @BeforeMethod%0A  public void setUp() %7B%0A    eventDispatcher = new EventDispatcher();%0A%0A    peerInfo = mock(PeerInformation.class);%0A    pieceInfo = mock(PieceInformation.class);%0A  %7D%0A%0A  public void testWithoutListeners() %7B%0A%0A    eventDispatcher.multicaster().downloadFailed(new RuntimeException());%0A    eventDispatcher.multicaster().peerConnected(peerInfo);%0A    eventDispatcher.multicaster().validationComplete(1, 4);%0A    eventDispatcher.multicaster().pieceDownloaded(pieceInfo, peerInfo);%0A    eventDispatcher.multicaster().downloadComplete();%0A    eventDispatcher.multicaster().pieceReceived(pieceInfo, peerInfo);%0A    eventDispatcher.multicaster().peerDisconnected(peerInfo);%0A  %7D%0A%0A  public void testInvocation() %7B%0A%0A    final AtomicInteger invocationCount = new AtomicInteger();%0A    int count = 5;%0A    for (int i = 0; i %3C count; i++) %7B%0A      eventDispatcher.addListener(new TorrentListenerWrapper() %7B%0A        @Override%0A        public void downloadComplete() %7B%0A          invocationCount.incrementAndGet();%0A        %7D%0A      %7D);%0A    %7D%0A%0A    eventDispatcher.multicaster().peerConnected(peerInfo);%0A%0A    assertEquals(invocationCount.get(), 0);%0A%0A    eventDispatcher.multicaster().downloadComplete();%0A%0A    assertEquals(invocationCount.get(), count);%0A%0A  %7D%0A%7D%0A

add test for event dispatcher