Created
December 3, 2013 12:23
-
-
Save myzone/7768360 to your computer and use it in GitHub Desktop.
Declarative java :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.myzone.nopebook; | |
import java.util.function.Function; | |
import static org.mockito.Matchers.*; | |
import static org.mockito.Mockito.*; | |
/** | |
* Created by myzone on 12/3/13. | |
*/ | |
public class FibTest { | |
public static void main(String[] args) { | |
Function<Integer, Integer> fib = mock(Function.class); | |
doAnswer(invocation -> { | |
Integer i = (Integer) invocation.getArguments()[0]; | |
return fib.apply(i - 2) + fib.apply(i - 1); | |
}).when(fib).apply(any(Integer.class)); | |
doReturn(1).when(fib).apply(eq(1)); | |
doReturn(1).when(fib).apply(eq(2)); | |
System.out.println(fib.apply(10)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment