Skip to content
Snippets Groups Projects
Commit b67e34f0 authored by Trym Hamer Gudvangen's avatar Trym Hamer Gudvangen
Browse files

Merge branch 'test/more' into 'feat/part-three'

test: Playthrough, GoalFactory and TextValidation

See merge request !31
parents 7d1f9663 138cf7bb
No related branches found
No related tags found
2 merge requests!31test: Playthrough, GoalFactory and TextValidation,!7Feat/part three
Pipeline #230357 passed
......@@ -70,7 +70,7 @@ public class Playthrough {
return;
}
if (!currentPassage.hasLinks()) {
if (currentPassage != null && !currentPassage.hasLinks()) {
gameState = PlaythroughState.STUCK;
}
}
......
package edu.ntnu.idatt2001.group_30.paths.model;
import static org.junit.jupiter.api.Assertions.*;
import edu.ntnu.idatt2001.group_30.paths.model.goals.Goal;
import edu.ntnu.idatt2001.group_30.paths.model.goals.GoldGoal;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class PlaythroughTest {
private Playthrough playthrough;
private Passage openingPassage;
@BeforeEach
void setUp() {
openingPassage = new Passage("Opening passage", "This is the opening passage");
Player player = new Player("Player", 10, 20, 30);
Story story = new Story("My story", openingPassage);
List<Goal> goals = List.of(new GoldGoal(50));
Game game = new Game(player, story, goals);
playthrough = new Playthrough(game);
}
@Test
void testBeginPlaythrough() {
PlaythroughState state = playthrough.beginPlaythrough();
assertEquals(PlaythroughState.STUCK, state);
assertEquals(openingPassage, playthrough.getCurrentPassage());
}
@Test
void testMakeTurn() {
playthrough.beginPlaythrough();
Link link = new Link("Link", "Passage123");
PlaythroughState state = playthrough.makeTurn(link);
assertEquals(PlaythroughState.STUCK, state);
}
@Test
void testMakeTurnWithNullLink() {
assertThrows(NullPointerException.class, () -> playthrough.makeTurn(null));
}
}
package edu.ntnu.idatt2001.group_30.paths.model.goals;
import static org.junit.jupiter.api.Assertions.*;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
class GoalFactoryTest {
/*
* this is a factory class, so the typical beforeEach arrange step is not needed
*/
@ParameterizedTest
@MethodSource("validGoalTypeAndValueProvider")
void getGoal_withValidGoalTypeAndValue_returnsGoalObject() {
GoalType goalType = GoalType.GOLD_GOAL;
Object goalValue = "100";
Goal<?> goal = GoalFactory.getGoal(goalType, goalValue);
assertEquals(GoldGoal.class, goal.getClass());
}
private static Stream<Arguments> validGoalTypeAndValueProvider() {
return Stream.of(
Arguments.of(GoalType.GOLD_GOAL, "100", GoldGoal.class),
Arguments.of(GoalType.HEALTH_GOAL, "50", HealthGoal.class),
Arguments.of(GoalType.SCORE_GOAL, "500", ScoreGoal.class)
);
}
@ParameterizedTest
@MethodSource("invalidGoalTypeAndValueProvider")
void getGoal_withInvalidGoalValue_throwsIllegalArgumentException() {
GoalType goalType = GoalType.GOLD_GOAL;
Object goalValue = "invalid_value";
assertThrows(IllegalArgumentException.class, () -> GoalFactory.getGoal(goalType, goalValue));
}
private static Stream<Arguments> invalidGoalTypeAndValueProvider() {
return Stream.of(
Arguments.of(GoalType.GOLD_GOAL, "invalid", GoldGoal.class),
Arguments.of(GoalType.HEALTH_GOAL, "-1", HealthGoal.class),
Arguments.of(GoalType.SCORE_GOAL, "", ScoreGoal.class)
);
}
}
package edu.ntnu.idatt2001.group_30.paths.model.utils;
import javafx.scene.control.TextFormatter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
class TextValidationTest {
@Test
void createIntegerTextFormatter_should_return_formatter_with_default_start_value() {
int expectedStartValue = 100;
TextFormatter<Integer> formatter = TextValidation.createIntegerTextFormatter();
Assertions.assertEquals(expectedStartValue, formatter.getValue());
}
@Test
void createIntegerTextFormatter_should_return_formatter_with_custom_start_value() {
int startValue = 50;
TextFormatter<Integer> formatter = TextValidation.createIntegerTextFormatter(startValue);
Assertions.assertEquals(startValue, formatter.getValue());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment