Coverage Report - biz.xsoftware.examples.fullapi.TestExample
 
Classes in this File Line Coverage Branch Coverage Complexity
TestExample
100%
15/15
N/A
0
 
 1  
 /*
 2  
  * Created on Jun 28, 2004
 3  
  *
 4  
  * To change the template for this generated file go to
 5  
  * Window - Preferences - Java - Code Generation - Code and Comments
 6  
  */
 7  
 package biz.xsoftware.examples.fullapi;
 8  
 
 9  
 import junit.framework.TestCase;
 10  
 import biz.xsoftware.mock.CalledMethod;
 11  
 import biz.xsoftware.mock.MockObjectFactory;
 12  
 import biz.xsoftware.mock.MockObject;
 13  
 
 14  
 /**
 15  
  * JUnit Suite of TestCases for demonstrating mocking out a more
 16  
  * complex api.
 17  
  * 
 18  
  * @author Dean Hiller
 19  
  */
 20  
 public class TestExample extends TestCase {
 21  
 
 22  
         private EmailToPhone sysUnderTest;
 23  
         private MockObject mockPhoneFactory;
 24  
         private MockObject mockPhone;
 25  
         
 26  
         /**
 27  
          * @showcode
 28  
          */
 29  
         public TestExample(String name) {
 30  1
                 super(name);
 31  1
         }
 32  
 
 33  
         /**
 34  
          * @showcode
 35  
          */
 36  
         @Override
 37  
     public void setUp() {
 38  1
                 mockPhoneFactory = MockObjectFactory.createMock(PhoneFactory.class);
 39  1
                 mockPhone = MockObjectFactory.createMock(Phone.class);
 40  
                 
 41  1
                 sysUnderTest = new EmailToPhoneImpl((PhoneFactory)mockPhoneFactory);
 42  1
         }
 43  
         
 44  
         /**
 45  
          * Some api's can be more OO oriented then others and have no
 46  
          * one facade into the whole subsystem as it may be too large, 
 47  
          * so this demonstrates how even those api's can be mocked out.
 48  
          * 
 49  
          * This also demonstrates a susbystem that relies on two subsystems
 50  
          * such that you can trigger an event in one subsystem and test
 51  
          * the interaction with the other subsystem.
 52  
          * 
 53  
          * @showcode
 54  
          */
 55  
         public void testReceiveHighPriorityEmail() {
 56  
         
 57  
         //We know that when receivedHighPriorityEmail is called, the EmailToPhone system will
 58  
         //create a Phone so we need to make sure the mock object's passes back a mockPhone
 59  
         //that the test controls
 60  1
         mockPhoneFactory.addReturnValue("createPhone", mockPhone);
 61  
         
 62  1
         String extension = "555-4444";
 63  1
                 String emailTitle = "xxxx";
 64  1
         String emailContents = "yyyy";
 65  1
                 sysUnderTest.receivedHighPriorityEmail(extension, emailTitle, emailContents);
 66  
                 
 67  
         //we expect createPhone to be called
 68  1
                 mockPhoneFactory.expect("createPhone");
 69  
         
 70  
         //we expect a phone call to be made to the correct extension
 71  1
                 CalledMethod m = mockPhone.expect("makeCall");
 72  1
         assertEquals(extension, m.getAllParams()[0]);
 73  1
         }
 74  
 }