Coverage Summary for Class: Card03 (it.polimi.ingsw.Model)

Class Class, % Method, % Branch, % Line, %
Card03 100% (1/1) 100% (3/3) 83,3% (10/12) 93,8% (15/16)


1 package it.polimi.ingsw.Model; 2  3 import it.polimi.ingsw.Exceptions.Input.InputValidationException; 4 import it.polimi.ingsw.Exceptions.Input.InvalidElementException; 5 import it.polimi.ingsw.Exceptions.Operation.FailedOperationException; 6 import it.polimi.ingsw.Misc.OptionalValue; 7  8 import java.io.Serial; 9  10 /** 11  * EFFECT: Choose an Island and resolve the Island as if 12  * Mother Nature had ended her movement there. Mother 13  * Nature will still move and the Island where she ends 14  * her movement will also be resolved. 15  */ 16 public class Card03 extends StatelessEffect { 17  @Serial 18  private static final long serialVersionUID = 105L; // convention: 1 for model, (01 -> 99) for objects 19  20  public Card03(Model ctx) { 21  super(3, 3, ctx); 22  } 23  24  /** 25  * Refer to: {@link CharacterCard#overridableCheckInput(CharacterCardInput)} for further information 26  * 27  * @param input CharacterCardInput should contain: 28  * <ul> 29  * <li>A valid island's ID </li> 30  * </ul> 31  */ 32  public OptionalValue<InputValidationException> overridableCheckInput(CharacterCardInput input) { 33  if (input.getTargetIsland().isEmpty()) { 34  return OptionalValue.of(new InvalidElementException("Target Island")); // target ti not set 35  } 36  Island ti = input.getTargetIsland().get(); 37  int tiID = ti.getId(); 38  if (tiID < 0 || tiID >= 12) { 39  return OptionalValue.of(new InvalidElementException("Target Island")); // target ti out of bounds for id 40  } 41  if (!this.context.getMutableIslandField().getMutableIslands().contains(ti)) { 42  return OptionalValue.of(new InvalidElementException("Target Island")); // target ti not in field 43  } 44  return OptionalValue.empty(); 45  } 46  47  /** 48  * Refer to: {@link CharacterCard#unsafeApplyEffect(CharacterCardInput)} for further information 49  */ 50  @Override 51  protected void unsafeApplyEffect(CharacterCardInput input) throws Exception { 52  Island ti = input.getTargetIsland().get(); 53  for (IslandGroup ig : this.context.getMutableIslandField().getMutableGroups()) { 54  if (ig.contains(ti)) { 55  context.actMotherNaturePower(ig); 56  return; 57  } 58  } 59  throw new FailedOperationException("Card03.unsafeApplyEffect", "Target Island was not contained in any IslandGroup"); 60  } 61  62  //test purpose only 63 }