Guest User

Untitled

a guest
Jul 20th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. /*fake method that returns a string simulating a database query*/
  2. def fake_dependancy() : String = "gazorpian"
  3.  
  4. /*function that needs to be tested*/
  5. def method_that_takes_dependancy(dependancy:() => String) = (name:String) => {
  6. val alien_name = dependancy()
  7. name == alien_name
  8. }
  9. /*We first pass in the fake dependancy to the method, which returns a new function containing all the logic we need to test*/
  10. val function_whose_logic_needs_to_be_tested = method_that_takes_dependancy(fake_dependancy)
  11. println(function_whose_logic_needs_to_be_tested("gazorpian")) //returns : true
Add Comment
Please, Sign In to add comment