Scala and Mockito with traits

后端 未结 1 1770
滥情空心
滥情空心 2021-01-05 06:31

I had a simple class that naturally divided into two parts, so I refactored as

class Refactored extends PartOne with PartTwo

Then the unit

相关标签:
1条回答
  • 2021-01-05 07:06

    Seems Mockito has some kind of problem seeing the relationship between class and trait. Guess this is not that strange since traits are not native in Java. It works if you mock the trait itself directly, but this is maybe not what you want to do? With several different traits you would need one mock for each:

    @Test def third_PASSES {
      val mockThird = mock[Third_B]
    
      when(mockThird.getSomething(mockA)).thenReturn(3)
    
      assert(3 === mockThird.getSomething(mockA))
    }
    
    0 讨论(0)
提交回复
热议问题