Hi i have a class like this
class MyClass { private ExternalClass1 ex1; private ExternalClass2 ex2; private ExternalClass3 ex3 public String doSomething(String arg1){ val1=ex1.invoke(arg1); val2=ex2.call(val1); result=ex3.doit(val2); return result; } } unit test of this method
@Test void doSometing(){ ExternalClass1 ex1=mock(ExternalClass1); ExternalClass2 ex2=mock(ExternalClass2); ExternalClass3 ex3=mock(ExternalClass2); when(ex1.invoke(arg1)).thenReturn(val1); when(ex2.call(val1)).thenReturn(val2); when(ex3.doit(val2)).thenReturn(result); Myclass myClass=new MyClass(ex1,ex2,ex3); assertEquals(result,myClass.doSomething(arg1)) } The test code of this method seems to be a simple repetition of the code itself, but more complex. Does the test of this kind of class whose role is to control other classes brings any value?
Thank's
doSomethingto me. A proper unit test ofdoSomethingwould simply calldoSomethingwith some test value and assert the expected return result.