package es.sandbox.spikes.java8.interfaces;

import es.sandbox.spikes.java8.InvocationSpy;
import org.junit.Before;
import org.junit.Test;

import java.lang.reflect.Method;

import static es.sandbox.spikes.java8.FunctionalInterfaceCaller.call;
import static es.sandbox.spikes.java8.InvocationSpy.spy;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * Created by jeslopalo on 30/12/15.
 */
public class FunctionalInterfaceSpecs {

    private InvocationSpy spy;

    @Before
    public void setup() {
        this.spy = spy();
    }

    @Test
    public void has_only_one_declared_method() {
        final Method[] methods = SimpleFunctionalInterface.class.getDeclaredMethods();

        assertThat(methods).hasSize(1);
    }

    @Test
    public void when_is_used_in_a_lambda_it_invokes_the_unique_declared_method() {
        call(() -> this.spy.invocation());

        assertThat(this.spy.invoked()).isTrue();
    }
}

package es.sandbox.spikes.java8.interfaces;

import es.sandbox.spikes.java8.InvocationSpy;
import org.junit.Before;
import org.junit.Test;

import static es.sandbox.spikes.java8.FunctionalInterfaceCaller.call;
import static es.sandbox.spikes.java8.InvocationSpy.spy;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * Created by jeslopalo on 30/12/15.
 */
public class FunctionalInterfaceSpecs {

    private InvocationSpy spy;

    @Before
    public void setup() {
        this.spy = spy();
    }

    @Test
    public void has_one_callable_method() {
        call(() -> this.spy.invocation());

        assertThat(this.spy.invoked()).isTrue();
    }
}

--- 
+++ 
@@ -3,6 +3,8 @@
 import es.sandbox.spikes.java8.InvocationSpy;
 import org.junit.Before;
 import org.junit.Test;
+
+import java.lang.reflect.Method;
 
 import static es.sandbox.spikes.java8.FunctionalInterfaceCaller.call;
 import static es.sandbox.spikes.java8.InvocationSpy.spy;
@@ -21,7 +23,14 @@
     }
 
     @Test
-    public void has_one_callable_method() {
+    public void has_only_one_declared_method() {
+        final Method[] methods = SimpleFunctionalInterface.class.getDeclaredMethods();
+
+        assertThat(methods).hasSize(1);
+    }
+
+    @Test
+    public void when_is_used_in_a_lambda_it_invokes_the_unique_declared_method() {
         call(() -> this.spy.invocation());
 
         assertThat(this.spy.invoked()).isTrue();
Test that Functional Interfaces has only one declared method
