Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*fake method that returns a string simulating a database query*/
- def fake_dependancy() : String = "gazorpian"
- /*function that needs to be tested*/
- def method_that_takes_dependancy(dependancy:() => String) = (name:String) => {
- val alien_name = dependancy()
- name == alien_name
- }
- /*We first pass in the fake dependancy to the method, which returns a new function containing all the logic we need to test*/
- val function_whose_logic_needs_to_be_tested = method_that_takes_dependancy(fake_dependancy)
- println(function_whose_logic_needs_to_be_tested("gazorpian")) //returns : true
Add Comment
Please, Sign In to add comment