package com.github.blackrush.acara.dispatch;

import org.fungsi.Either;
import org.junit.Test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

public class TypedDispatcherTest {
    @Test
    public void testInstantiationViaClass() throws Exception {
        class StringDispatcher extends TypedDispatcher<String> {
            @Override
            protected Either<Object, Throwable> dispatch0(Object listener, String event) {
                return Either.left(null);
            }
        }

        TypedDispatcher<String> d = new StringDispatcher();

        assertThat("dispatcher event class", d.eventClass, equalTo(String.class));
    }

    @Test
    public void testInstantiationViaAnonymous() throws Exception {
        TypedDispatcher<String> d = new TypedDispatcher<String>() {
            @Override
            protected Either<Object, Throwable> dispatch0(Object listener, String event) {
                return Either.left(null);
            }
        };

        assertThat("dispatcher event class", d.eventClass, equalTo(String.class));
    }

    @Test(expected = IllegalStateException.class)
    public void testInstantiationError() throws Exception {
        class InvalidDispatcher<T> extends TypedDispatcher<T> {
            @Override
            protected Either<Object, Throwable> dispatch0(Object listener, T event) {
                return Either.left(null);
            }
        }

        new InvalidDispatcher<String>();
    }
}
@@ -89,16 +89,141 @@
 .Test;%0A%0A
+import static org.fungsi.Unit.unit;%0Aimport static org.hamcrest.CoreMatchers.is;%0Aimport static org.hamcrest.CoreMatchers.isA;%0A
 import s
@@ -356,85 +356,8 @@
 t %7B%0A
-    @Test%0A    public void testInstantiationViaClass() throws Exception %7B%0A    
     
@@ -413,36 +413,32 @@
 ring%3E %7B%0A        
-    
 @Override%0A      
@@ -423,36 +423,32 @@
       @Override%0A
-    
         protecte
@@ -522,36 +522,32 @@
 ) %7B%0A            
-   
- 
 return Either.le
@@ -564,32 +564,97 @@
         
+%7D%0A
     %7D%0A
+%0A
     
-    %7D%0A
+@Test%0A    public void testInstantiationViaClass() throws Exception %7B
 %0A       
@@ -1608,10 +1608,604 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testDispatch() throws Exception %7B%0A        TypedDispatcher%3CString%3E d = new StringDispatcher();%0A%0A        Either%3CObject, Throwable%3E res = d.dispatch(unit(), %22lol%22);%0A%0A        assertThat(%22result is a success%22, res.isLeft(), is(true));%0A    %7D%0A%0A    @SuppressWarnings(%22unchecked%22)%0A    @Test%0A    public void testInvalidDispatch() throws Exception %7B%0A        TypedDispatcher%3CString%3E d = new StringDispatcher();%0A%0A        Either%3CObject, Throwable%3E res = d.dispatch(unit(), 42);%0A%0A        assertThat(%22result failure%22, res.right(), isA((Class) IllegalArgumentException.class));%0A    %7D
 %0A%7D

add TypedDispatcher tests