??

    ???????????????????????????????????????????????????Working Effectively with legacy Code ????????????1???????????????е????????????????н????????????????????????????????????????±???????????????????????????????????????RGHConnection????????????????????????????????????????α???RGHConnection?????CreditValidator?????????????????RGHConnection???????????????????????????

???????????????RGHConnection????е??????

RGHConnection
+ RGHConnection(port??name??password)
+ connect()
+ disconnect()
+RFDIReportFor(id:int):RFDIReport
+ACTIOReportFor(customerID:int) ACTIOReport
+retry()
+fromPacket():RFPacket

?????????RGHConnection?????Щ????????????????????????????????connect??disconnect???retry?????????Щ??????????????α?????RGHConnection??????????????α????????????????Щ???????????????????

????????Щ?????£?α?????RGHConnection????????????RGHConnection????y?????????????????????????????????????????????????????????????????????????????????

<interface>
IRGHConnection
+connect()
+ disconnect()
+RFDIReportFor(id:int):RFDIReport
+ACTIOReportFor(customerID:int) ACTIOReport


????????retry()??fromPacket()???????????????????????????????????????????????????????????????????????FackeConnection?????????????????????????????????????α??????????????У?

public class FakeConnection implements IRGHConnection
{
    public  RFDIReport report;
    public void connect() {}
    public void disconnnect(){}
    public RFDIReport RFDReportFor(int id) {return report;}
    public ACTIOReport ACTIOReportFor(int customerID) {return null;}
}

??????????????д????

void testNoSuccess()throws Exception{
  CreditMaster master = new CreditMaster("crm2.mas"??true);
  IRGHConnection connection = new FakeConnection();
  CreditValidator validator = new CreditValidator(connection??master??"a");
  connection.report = new RFDReport(....);
  Certificate result = validator.validatorCustomer(new Customer(...));
  assertEquals(Certificate.VALID??result.getStatus());
}

???????FakeConnection???????е???????????????????????????null?????????β?????????????????????????κ??????????????????????????????????????????????Υ???????е????????????????????????????????????????????ò?????е?????????????????FakeConnection?е????????????????????????????????е??????????????????????????????

???????????fake?????????????????????????????????????????????????????????????????????????????????????????ν?RGHConnection?????????????????????л???????????????????????????????????