I have a method called GetValueA() and GetValueB() which return string that in formatted
public string GetValueA(){
string a = service1.GetA();
return Format(a);
}
public string GetValueB(){
string b = service2.GetB();
return Format(b)
}
private Format(string unformatted){
return unformatted.ReplaceSpace().PaddingZero() // for example " 123" will be "00123"
}
when I create unit test I create
GivenA_WhenGetA_ReturnFormattedA() // with test data "123", " 123", " 12 3"
GivenB_WhenGetB_ReturnFormattedB() // with test data "123", " 123", " 12 3"
from above it seems the same so if I public private Format()
public class Formatter : IFormatter
{
public string Format(string data);
}
and create unit test
GivenDataHaveSpace_WhenFormatString_ReturnDataWithNoSpace();
GivenDataLessThanFiveDigits_WhenFormatString_ReturnDataWithPaddingZero();
and use it in GetValueA and GetValueB
public string GetValueA(){
string a = service1.GetA();
return IFormatter.Format(a);
}
public string GetValueB(){
string b = service2.GetB();
return IFormatter.Format(b)
}
the question are
if I use IFormatter instead of private it looks like all responsibility is rely on IFormatter and testing
GivenA_WhenGetA_ReturnFormattedA() // with test data "123", " 123", " 12 3" GivenB_WhenGetB_ReturnFormattedB() // with test data "123", " 123", " 12 3"
will rely on mock of
IFormatter
which is act as the same as I set up.1.1 Should I keep this, to say these methods need two format data after get from service?
1.2 or just remove them because when I have something the same with
GetValueD
,GetValueE
,GetValueF
,GetValueG
will make this redundant.Is it make sense if I go with private
Format()
method instead?