Merge pull request #6093 from urvyagrawal/BAEL-2543

Adding files for BAEL-2543
This commit is contained in:
Eric Martin 2019-01-12 17:12:13 -06:00 committed by GitHub
commit 8f938c54a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,5 @@
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,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);
}
}