BAEL-4936: Added getColor() method in CircleInterface class as per the review comment
This commit is contained in:
parent
b1c13e893b
commit
12dc1287a5
|
@ -3,6 +3,7 @@ package com.baeldung.interfaceVsAbstractClass;
|
|||
public class ChidlCircleInterfaceImpl implements CircleInterface {
|
||||
private String color;
|
||||
|
||||
@Override
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
|
|
@ -6,8 +6,10 @@ import java.util.List;
|
|||
public interface CircleInterface {
|
||||
List<String> allowedColors = Arrays.asList("RED", "GREEN", "BLUE");
|
||||
|
||||
public default boolean isValid(String color) {
|
||||
if (allowedColors.contains(color)) {
|
||||
String getColor();
|
||||
|
||||
public default boolean isValid() {
|
||||
if (allowedColors.contains(getColor())) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
|
@ -16,6 +16,6 @@ public class InterfaceVsAbstractClassUnitTest {
|
|||
public void givenInterface_whenValidCircleWithoutStateUsedThenPass() {
|
||||
ChidlCircleInterfaceImpl redCircleWithoutState = new ChidlCircleInterfaceImpl();
|
||||
redCircleWithoutState.setColor("RED");
|
||||
assertTrue(redCircleWithoutState.isValid(redCircleWithoutState.getColor()));
|
||||
assertTrue(redCircleWithoutState.isValid());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue