java - Refactoring to expose private methods for unit testing -
i have class process string , many actions on turn turn.
those actions need done in specific order.
example:
public string process(string stringtoprocess) throws exception { processedstring = process1(processedstring); processedstring = process2(processedstring); processedstring = process3(processedstring); processedstring = process4(processedstring); ... processedstring = process10(processedstring); ... return processedstring; }
i'm sure there better way refactor make cleaner, of all, want able unit test process1, process2 etc.
note process1, 2 etc... can whether 2 line methods or big ones.
i need process methods somehow public test them. there design pattern achieve this?
i thought using enums achieve this, thought somehow making more confusing. implementation not best sure, @ 1 glance, know what's happening.
edit: approach not bad me, process methods should private. , want unit test them. saw question, can test them if private, first step make sure couldn't done better.
you may take @ http://www.codeproject.com/articles/455228/design-patterns-3-of-3-behavioral-design-patterns#chain maybe it's kind of overkill task.
what extract process1
, process2
etc separate classes. can a) test them unit tests separately b) inject them class , use them in process
method in necessary order.
take post: design pattern multi-step algorithm maybe ideas there.
Comments
Post a Comment