Hallo ich habe ein etwas seltsames Verhalten :
Ich habe ein Interface :
Nun gibt es einen Standart Controller, der nur addElement und getElement enthalten darf. Daher wird eine RuntimeException geworfen, wenn remove aufgerufen wird :
Ein weiterer Controller darf diese Funktion aber anbieten und erweitert den Standart Controller :
Rufe ich jedoch die Funktion remove in einem Test auf, so bekomme ich eine RuntimeException (aus der Etltenklasse).
Kann mir jemand weiterhelfen
Vielen Dank
Ich habe ein Interface :
Java:
public interface Controller<T extends ControllerObject> {
/**
* @return a element list <br>
*/
public List<T> getElementList();
/**
* try to add a new {@link ControllerObject} to the list <br>
* if the new element exists already in the list return the existing one <br>
* otherwise return the new element <br>
*
* @return the existsing or the new created element <br>
**/
public T addElement(T element);
/**
* remove a {@link ControllerObject} of the list <br>
*/
public void removeElement(T element);
Nun gibt es einen Standart Controller, der nur addElement und getElement enthalten darf. Daher wird eine RuntimeException geworfen, wenn remove aufgerufen wird :
Java:
public class TeamController implements Controller<Team> {
@NonNull
@Setter(AccessLevel.NONE)
@Getter(AccessLevel.NONE)
protected final List<Team> teamList = Lists.newArrayList();
/**
* @return a copy of the teamList <br>
*/
@Override
public List<Team> getElementList() {
return Lists.newArrayList(teamList);
}
/**
* try to add a new {@link Team} to the list <br>
* if the team exists already in the list return it <br>
* otherwise return the new team <br>
*
* @return the existsing or the new created team <br>
*/
@Override
public Team addElement(@NonNull Team element) {
Optional<Team> optional = teamList.stream().filter(e -> e.equals(element)).findFirst();
Team tmpTeam = null;
if (optional.isPresent()) {
log.debug("the team [{}] exists already in the teamList", element);
tmpTeam = optional.get();
} else {
log.info("add the team [{}] into the teamList", element);
tmpTeam = element;
teamList.add(element);
}
return tmpTeam;
}
@Override
public void removeElement(@NonNull Team element) {
throw new RuntimeException("non supported function");
}
}
Ein weiterer Controller darf diese Funktion aber anbieten und erweitert den Standart Controller :
Java:
public class FullTeamController extends TeamController {
/**
* remove a team from the list <br>
*/
public void removeElement(@NonNull VolleyballTeam team) {
Optional<Team> optional = teamList.stream().filter(e -> e.equals(team)).findFirst();
if (optional.isPresent()) {
log.info("remove the team [{}] from the teamList", team);
teamList.remove(team);
}
}
}
Rufe ich jedoch die Funktion remove in einem Test auf, so bekomme ich eine RuntimeException (aus der Etltenklasse).
Kann mir jemand weiterhelfen
Vielen Dank