Source code (test) - Guide to Inheritance in Java

This commit is contained in:
MalaguptaBaeldung 2018-02-25 08:08:12 -08:00 committed by GitHub
parent dffe5cb81d
commit e789eaa9ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,46 @@
package com.baeldung.inheritance;
import com.baeldung.inheritance.*;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
public class AppTest extends TestCase {
public AppTest(String testName) {
super( testName );
}
public static Test suite() {
return new TestSuite(AppTest.class);
}
@SuppressWarnings("static-access")
public void testStaticMethodUsingBaseClassVariable() {
Car first = new ArmoredCar();
assertEquals("Car", first.msg());
}
@SuppressWarnings("static-access")
public void testStaticMethodUsingDerivedClassVariable() {
ArmoredCar second = new ArmoredCar();
assertEquals("ArmoredCar", second.msg());
}
public void testAssignArmoredCarToCar() {
Employee e1 = new Employee("Shreya", new ArmoredCar());
assertNotNull(e1.getCar());
}
public void testAssignSpaceCarToCar() {
Employee e2 = new Employee("Paul", new SpaceCar());
assertNotNull(e2.getCar());
}
public void testBMWToCar() {
Employee e3 = new Employee("Pavni", new BMW());
assertNotNull(e3.getCar());
}
}