Adding files for BAEL-2543

This commit is contained in:
Urvy Agrawal 2019-01-07 22:03:52 +05:30
parent 0e69cd5ab4
commit 115a52a124
6 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,4 @@
package com.baeldung.keyword;
public class Circle extends Round implements Shape {
}

View File

@ -0,0 +1,4 @@
package com.baeldung.keyword;
public class Ring extends Round {
}

View File

@ -0,0 +1,4 @@
package com.baeldung.keyword;
public class Round {
}

View File

@ -0,0 +1,4 @@
package com.baeldung.keyword;
public interface Shape {
}

View File

@ -0,0 +1,4 @@
package com.baeldung.keyword;
public class Triangle implements Shape {
}

View File

@ -0,0 +1,49 @@
package com.baeldung.keyword.test;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import com.baeldung.keyword.Circle;
import com.baeldung.keyword.Ring;
import com.baeldung.keyword.Round;
import com.baeldung.keyword.Shape;
import com.baeldung.keyword.Triangle;
public class InstanceOfUnitTest {
@Test
public void giveWhenInstanceIsCorrect_thenReturnTrue() {
Ring ring = new Ring();
Assert.assertTrue("ring is instance of Round ", ring instanceof Round);
}
@Test
public void giveWhenObjectIsInstanceOfType_thenReturnTrue() {
Circle circle = new Circle();
Assert.assertTrue("circle is instance of Circle ", circle instanceof Circle);
}
@Test
public void giveWhenInstanceIsOfSubtype_thenReturnTrue() {
Circle circle = new Circle();
Assert.assertTrue("circle is instance of Round", circle instanceof Round);
}
@Test
public void giveWhenTypeIsInterface_thenReturnTrue() {
Circle circle = new Circle();
Assert.assertTrue("circle is instance of Shape", circle instanceof Shape);
}
@Test
public void giveWhenInstanceValueIsNull_thenReturnFalse() {
Circle circle = null;
Assert.assertFalse("circle is instance of Round", circle instanceof Round);
}
@Test
public void giveWhenComparingClassInDiffHierarchy_thenCompilationError() {
// Assert.assertFalse("circle is instance of Triangle", circle instanceof Triangle);
}
}