Skip to content

Instantly share code, notes, and snippets.

@myzone
Created December 3, 2013 12:23
Show Gist options
  • Save myzone/7768360 to your computer and use it in GitHub Desktop.
Save myzone/7768360 to your computer and use it in GitHub Desktop.
Declarative java :)
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