Merge pull request #6262 from soufiane-cheouati/master
Adding marker interfaces files
This commit is contained in:
commit
c9fd46e693
@ -0,0 +1,5 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
public interface DeletableShape extends Shape {
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
public class Rectangle implements DeletableShape {
|
||||
|
||||
private double width;
|
||||
private double height;
|
||||
|
||||
public Rectangle(double width, double height) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getArea() {
|
||||
return width * height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getCircumference() {
|
||||
return 2 * (width + height);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
public interface Shape {
|
||||
double getArea();
|
||||
double getCircumference();
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
public class ShapeDao {
|
||||
|
||||
public boolean delete(Object object) {
|
||||
if (!(object instanceof DeletableShape)) {
|
||||
return false;
|
||||
}
|
||||
// Calling the code that deletes the entity from the database
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package com.baeldung.markerinterface;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MarkerInterfaceUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenDeletableObjectThenTrueReturned() {
|
||||
ShapeDao shapeDao = new ShapeDao();
|
||||
Object rectangle = new Rectangle(2, 3);
|
||||
|
||||
boolean result = shapeDao.delete(rectangle);
|
||||
assertEquals(true, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNonDeletableObjectThenFalseReturned() {
|
||||
ShapeDao shapeDao = new ShapeDao();
|
||||
Object object = new Object();
|
||||
|
||||
boolean result = shapeDao.delete(object);
|
||||
assertEquals(false, result);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user