????????????????????????????????????????????滻??????????
?????????????? class Application {
????...
????public void run() {
????View v = new View();
????v.display();
????...
???????????????????????????????????????????????и???ù???????????????????????????????????????????????????????????????????????????????????????????
??????????????
????class Application {
????...
????public void run() {
????View v = createView();
????v.display();
????...
????protected View createView() {
????return new View();
????}
????...
????}
??????????????嵥 1 ????????????????
?????嵥 1. ??????????
????class ApplicationTest extends TestCase {
????MockView mockView = new MockView();
????public void testApplication {
????Application a = new Application() {
????protected View createView() {
????return mockView;
????}
????};
????a.run();
????mockView.validate();
????}
????private class MockView extends View
????{
????boolean isDisplayed = false;
????public void display() {
????isDisplayed = true;
????}
????public void validate() {
????assertTrue(isDisplayed);
????}
????}
????}
???????
????????????????????е???????????н????
????????????????????? ???????????????????????????? ?????????????????????????????(?????) ?????????????????????????????????????????????????