/* CityEntryTest.java 1.0 */ /* by Sharon Tuttle */ /* last modified: 2-18-03 */ public class CityEntryTest extends JPFalt { public static void main(String[] args) { new CityEntryTest(); } /** Test suite for the abstract class CityEntry */ /*------------------------------------------------------------------------- Define an BusinessEntry object and print the member data values, and test accessor and modifier methods of BusinessEntry and CityEntry (note that CityEntry's modifier methods are indeed being implicitly tested, since BusinessEntry's constructor ends up calling them) ------------------------------------------------------------------------*/ void TestBusinessEntry() { println("\nDefine BusinessEntry object, print member data values"); BusinessEntry myEntry = new BusinessEntry("Japhy's Soup and Noodles", "123 5th Street", "123-4567", "Arcata", "CA"); println(myEntry); println(myEntry.getName()); println(myEntry.getAddress()); println(myEntry.getPhone()); println(myEntry.getCity()); println(myEntry.getState()); } /*------------------------------------------------------------------------- Define a ResidentialEntry object and print the member data values, and test accessor and modifier methods of ResidentialEntry and CityEntry ------------------------------------------------------------------------*/ void TestResidentialEntry() { println("\nDefine ResidentialEntry object, print member data values"); ResidentialEntry myEntry = new ResidentialEntry("Angela Smith", "123 5th Street", "123-4567"); println(myEntry); println(myEntry.getName()); println(myEntry.getAddress()); println(myEntry.getPhone()); } /*------------------------------------------------------------------ playWithInstanceof() Purpose: play around with Java's instanceof operator -------------------------------------------------------------------*/ void playWithInstanceof() { println("playing with instanceof"); ResidentialEntry roomMate = new ResidentialEntry("George", "Rm 335", "x4444"); // what types IS roomMate of, anyway? println("for ResidentialEntry instance:"); /* if (roomMate instanceof String) { println("...is of type String"); }*/ /* if (roomMate instanceof BusinessEntry) { println("...is of type BusinessEntry"); }*/ if (roomMate instanceof ResidentialEntry) { println("...is of type ResidentialEntry"); } if (roomMate instanceof CityEntry) { println("...is of type CityEntry"); } if (roomMate instanceof Object); { println("...is of type Object"); } } /*------------------------------------------------------------------------ Test method for isABusiness() (in abstract class CityEntry) -----------------------------------------------------------------------*/ void isABusinessTest() { BusinessEntry myEntry = new BusinessEntry("Japhy's Soup and Noodles", "123 5th Street", "123-4567", "Arcata", "CA"); ResidentialEntry myEntry2 = new ResidentialEntry("Jo", "rm 3", "x3383"); testHeader("isABusiness"); expected(true); actual(myEntry.isABusiness()); expected(false); actual(myEntry2.isABusiness()); } /*------------------------------------------------------------ Test method for abstract method specialToString() -------------------------------------------------------------*/ void specialToStringTest() { BusinessEntry myEntry = new BusinessEntry("Japhy's Soup and Noodles", "123 5th Street", "123-4567", "Arcata", "CA"); ResidentialEntry myEntry2 = new ResidentialEntry("Smith", "rm 3", "x3383"); testHeader("specialToStringTest"); expected("Japhy's Soup and Noodles.....Arcata 123-4567"); actual(myEntry.specialToString()); expected("Smith............x3383"); actual(myEntry2.specialToString()); } /*------------------------------------------------------------ Test method for method specialGetPhone() -------------------------------------------------------------*/ void specialGetPhoneTest() { BusinessEntry myEntry = new BusinessEntry("Japhy's Soup and Noodles", "123 5th Street", "123-4567", "Arcata", "CA"); ResidentialEntry myEntry2 = new ResidentialEntry("Smith", "rm 3", "x3383"); testHeader("specialGetPhoneTest"); expected("Arcata 123-4567"); actual(myEntry.specialGetPhone()); expected("Res x3383"); actual(myEntry2.specialGetPhone()); } }