Merge pull request #6093 from urvyagrawal/BAEL-2543
Adding files for BAEL-2543
This commit is contained in:
commit
8f938c54a9
|
@ -0,0 +1,5 @@
|
||||||
|
package com.baeldung.keyword;
|
||||||
|
|
||||||
|
public class Circle extends Round implements Shape {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.baeldung.keyword;
|
||||||
|
|
||||||
|
public class Ring extends Round {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.baeldung.keyword;
|
||||||
|
|
||||||
|
public class Round {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.baeldung.keyword;
|
||||||
|
|
||||||
|
public interface Shape {
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
package com.baeldung.keyword;
|
||||||
|
|
||||||
|
public class Triangle implements Shape {
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
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 giveWhenTypeIsOfObjectType_thenReturnTrue() {
|
||||||
|
Thread thread = new Thread();
|
||||||
|
Assert.assertTrue("thread is instance of Object", thread instanceof Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue