Adding files for BAEL-2543
This commit is contained in:
		
							parent
							
								
									0e69cd5ab4
								
							
						
					
					
						commit
						115a52a124
					
				
							
								
								
									
										4
									
								
								core-java/src/main/java/com/baeldung/keyword/Circle.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								core-java/src/main/java/com/baeldung/keyword/Circle.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | |||||||
|  | package com.baeldung.keyword; | ||||||
|  | 
 | ||||||
|  | public class Circle extends Round implements Shape { | ||||||
|  | } | ||||||
							
								
								
									
										4
									
								
								core-java/src/main/java/com/baeldung/keyword/Ring.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								core-java/src/main/java/com/baeldung/keyword/Ring.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | |||||||
|  | package com.baeldung.keyword; | ||||||
|  | 
 | ||||||
|  | public class Ring extends Round { | ||||||
|  | } | ||||||
							
								
								
									
										4
									
								
								core-java/src/main/java/com/baeldung/keyword/Round.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								core-java/src/main/java/com/baeldung/keyword/Round.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,4 @@ | |||||||
|  | package com.baeldung.keyword; | ||||||
|  | 
 | ||||||
|  | public class Round { | ||||||
|  | } | ||||||
							
								
								
									
										4
									
								
								core-java/src/main/java/com/baeldung/keyword/Shape.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								core-java/src/main/java/com/baeldung/keyword/Shape.java
									
									
									
									
									
										Normal file
									
								
							| @ -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,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); | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user