Skip to content

Commit c9fd46e

Browse files
authored
Merge pull request eugenp#6262 from soufiane-cheouati/master
Adding marker interfaces files
2 parents 231b8ad + afb46cd commit c9fd46e

File tree

5 files changed

+73
-0
lines changed

5 files changed

+73
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.baeldung.markerinterface;
2+
3+
public interface DeletableShape extends Shape {
4+
5+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.baeldung.markerinterface;
2+
3+
public class Rectangle implements DeletableShape {
4+
5+
private double width;
6+
private double height;
7+
8+
public Rectangle(double width, double height) {
9+
this.width = width;
10+
this.height = height;
11+
}
12+
13+
@Override
14+
public double getArea() {
15+
return width * height;
16+
}
17+
18+
@Override
19+
public double getCircumference() {
20+
return 2 * (width + height);
21+
}
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.baeldung.markerinterface;
2+
3+
public interface Shape {
4+
double getArea();
5+
double getCircumference();
6+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.markerinterface;
2+
3+
public class ShapeDao {
4+
5+
public boolean delete(Object object) {
6+
if (!(object instanceof DeletableShape)) {
7+
return false;
8+
}
9+
// Calling the code that deletes the entity from the database
10+
11+
return true;
12+
}
13+
14+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.baeldung.markerinterface;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
public class MarkerInterfaceUnitTest {
8+
9+
@Test
10+
public void givenDeletableObjectThenTrueReturned() {
11+
ShapeDao shapeDao = new ShapeDao();
12+
Object rectangle = new Rectangle(2, 3);
13+
14+
boolean result = shapeDao.delete(rectangle);
15+
assertEquals(true, result);
16+
}
17+
18+
@Test
19+
public void givenNonDeletableObjectThenFalseReturned() {
20+
ShapeDao shapeDao = new ShapeDao();
21+
Object object = new Object();
22+
23+
boolean result = shapeDao.delete(object);
24+
assertEquals(false, result);
25+
}
26+
}

0 commit comments

Comments
 (0)