@Test(expected = IllegalArgumentException.class) public void invalid_up_cast() { CatCage catCage = new CatCage(); PetCage cage = (PetCage) catCage; cage.enter(new Dog()); }
@Test public void empty() { PetCage cage = new PetCage(); PetCage catCage = new CatCage(); assertTrue(cage.isEmpty()); assertTrue(catCage.isEmpty()); Animal a = new Animal(); Cat c = new Cat(); cage.enter(a); catCage.enter(c); assertFalse(cage.isEmpty()); assertFalse(catCage.isEmpty()); cage.takeOut(); catCage.takeOut(); assertTrue(cage.isEmpty()); assertTrue(catCage.isEmpty()); }