/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.reflection.util;

import javax.xml.ws.Action;
import org.junit.Test;
import static net.ranides.assira.junit.NewAssert.*;
import net.ranides.assira.reflection.mockup.ForAnnotationUtils.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class AnnotationBuilderTest {
    
    @Test
    public void testJava() {
        Action ac1 = new AnnotationBuilder<>(Action.class)
            .param("input", "is")
            .param("output", "os")
            .result();
        
        assertEquals("is", ac1.input());
        assertEquals("os", ac1.output());
        
        Action ac2 = new AnnotationBuilder<>(Action.class)
            .param("input", 99)
            .param("output", 88)
            .result();
        
        assertThrows(ClassCastException.class, ()->{
            ac2.input();
        });
        assertThrows(ClassCastException.class, ()->{
            ac2.output();
        });
    }

    @Test
    public void testCustomBuilder() {
        MethodInfo mi1 = new AnnotationBuilder<>(MethodInfo.class)
            .param("name", "hello")
            .param("author", "ranides")
            .param("type", Float.class)
            .param("uid", 99)
            .param("api", API.ANSI)
            .result();
        
        MethodInfo mi2 = new AnnotationBuilder<>(MethodInfo.class)
            .param("name", "hello")
            .param("author", "ranides")
            .param("api", API.ANSI)
            .result();
        
        MethodInfo mi3 = new AnnotationBuilder<>(MethodInfo.class)
            .param("name", "hello")
            .param("author", "ranides")
            .param("type", null)
            .result();
        
        assertEquals("hello", mi1.name());
        assertEquals("ranides", mi1.author());
        assertEquals(Float.class, mi1.type());
        assertEquals(99, mi1.uid());
        assertEquals(API.ANSI, mi1.api());
        
        assertNotNull(mi1.toString());
        assertNotNull(mi1.hashCode());
        assertTrue(mi1.equals(mi1));
        
        assertEquals("hello", mi2.name());
        assertEquals("ranides", mi2.author());
        assertEquals(Integer.class, mi2.type());
        assertEquals(77, mi2.uid());
        assertEquals(API.ANSI, mi2.api());
        
        assertEquals("hello", mi3.name());
        assertEquals("ranides", mi3.author());
        assertEquals(null, mi3.type());
        assertEquals(77, mi3.uid());
        assertEquals(null, mi3.api());
        
    }

    
    
}
