Skip to content

Commit 115a52a

Browse files
author
Urvy Agrawal
committed
Adding files for BAEL-2543
1 parent 0e69cd5 commit 115a52a

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.baeldung.keyword;
2+
3+
public class Circle extends Round implements Shape {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.baeldung.keyword;
2+
3+
public class Ring extends Round {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.baeldung.keyword;
2+
3+
public class Round {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.baeldung.keyword;
2+
3+
public interface Shape {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package com.baeldung.keyword;
2+
3+
public class Triangle implements Shape {
4+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.baeldung.keyword.test;
2+
3+
import org.junit.Assert;
4+
import org.junit.jupiter.api.Test;
5+
6+
import com.baeldung.keyword.Circle;
7+
import com.baeldung.keyword.Ring;
8+
import com.baeldung.keyword.Round;
9+
import com.baeldung.keyword.Shape;
10+
import com.baeldung.keyword.Triangle;
11+
12+
public class InstanceOfUnitTest {
13+
14+
@Test
15+
public void giveWhenInstanceIsCorrect_thenReturnTrue() {
16+
Ring ring = new Ring();
17+
Assert.assertTrue("ring is instance of Round ", ring instanceof Round);
18+
}
19+
20+
@Test
21+
public void giveWhenObjectIsInstanceOfType_thenReturnTrue() {
22+
Circle circle = new Circle();
23+
Assert.assertTrue("circle is instance of Circle ", circle instanceof Circle);
24+
}
25+
26+
27+
@Test
28+
public void giveWhenInstanceIsOfSubtype_thenReturnTrue() {
29+
Circle circle = new Circle();
30+
Assert.assertTrue("circle is instance of Round", circle instanceof Round);
31+
}
32+
33+
@Test
34+
public void giveWhenTypeIsInterface_thenReturnTrue() {
35+
Circle circle = new Circle();
36+
Assert.assertTrue("circle is instance of Shape", circle instanceof Shape);
37+
}
38+
39+
@Test
40+
public void giveWhenInstanceValueIsNull_thenReturnFalse() {
41+
Circle circle = null;
42+
Assert.assertFalse("circle is instance of Round", circle instanceof Round);
43+
}
44+
45+
@Test
46+
public void giveWhenComparingClassInDiffHierarchy_thenCompilationError() {
47+
// Assert.assertFalse("circle is instance of Triangle", circle instanceof Triangle);
48+
}
49+
}

0 commit comments

Comments
 (0)