Create basic player #2
8
pom.xml
8
pom.xml
@ -13,5 +13,13 @@
|
|||||||
<maven.compiler.target>23</maven.compiler.target>
|
<maven.compiler.target>23</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>5.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@ -1,2 +1,24 @@
|
|||||||
public class Player {
|
public class Player {
|
||||||
|
private final String name;
|
||||||
|
private int health;
|
||||||
|
private int mana;
|
||||||
|
|
||||||
|
public Player(String name) {
|
||||||
|
this.name = name;
|
||||||
|
this.health = 100;
|
||||||
|
this.mana = 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHealth() {
|
||||||
|
return health;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMana() {
|
||||||
|
return mana;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/test/java/PlayerTest.java
Normal file
29
src/test/java/PlayerTest.java
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class PlayerTest {
|
||||||
|
|
||||||
|
private Player defaultPlayer() {
|
||||||
|
return new Player("abc");
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
void setNameOnCreation() {
|
||||||
|
var p = defaultPlayer();
|
||||||
|
assertEquals("abc", p.getName(), "Player name should have been set");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void setHealthOnCreation() {
|
||||||
|
var p = defaultPlayer();
|
||||||
|
assertEquals(100, p.getHealth(), "Player health should have been set");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void setsManaOnCreation() {
|
||||||
|
var p = defaultPlayer();
|
||||||
|
assertEquals(100, p.getMana(), "Player mana should have been set");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user