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

import java.util.function.Function;
import net.ranides.assira.functional.VarFunction;
import net.ranides.assira.reflection.IClass;
import net.ranides.assira.reflection.IMethod;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class AMethodTest {

    @Test
    public void testBind() {
        A a1 = new A(5);
        A a2 = new A(2);
        IMethod m0 = IClass.typeinfo(A.class).method("get").get();
        VarFunction m1 = m0.bind(a1);
        VarFunction m2 = m0.bind(a2);
        
        assertEquals(35, m0.apply(a1, 7));
        assertEquals(6, m0.apply(a2, 3));
        
        assertEquals(20, m1.call(4));
        assertEquals(10, m2.call(5));
        
        assertEquals(IClass.typeinfo(A.class).methods().require("get").list(), m0.collect().list() );
    }
    
    private static final class A {
        
        private int value;

        public A(int value) {
            this.value = value;
        }
        
        public int get(int ord) {
            return ord*value;
        }
        
    }
    
}
