Huh! It turned out that in the switched house :-).
Scala allows val in a particular class to override def in a tag.
My traits are becoming:
trait LabelMethods { def setText(text: String) //... } trait MainView { def someLabel: LabelMethods // Note that this member becomes // a def in this trait... def setVisible(visible: Boolean) // ... }
I do not need to change the MainFrame class:
class MainFrame extends JFrame with MainView { val someLabel = new JLabel with LabelMethods
My test code is as follows:
class TestMainPresenter { @Test def testPresenter { val mockLabel = EasyMock.createMock(classOf[LabelMethods]) val mockView = EasyMock.createMock(classOf[MainView]) EasyMock.expect(mockView.someLabel).andReturn(mockLabel)
Please note that I have not actually tested this, but it should work :-).
Ralph source share