Browse Source

Added Test to printAdminInfo Method from Admin Class

remotes/origin/fdai7780
Tobias Herbert 11 months ago
parent
commit
3f7c06bcff
  1. 14
      pom.xml
  2. 26
      src/test/java/org/example/AdminTest.java

14
pom.xml

@ -13,5 +13,19 @@
<maven.compiler.target>19</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

26
src/test/java/org/example/AdminTest.java

@ -0,0 +1,26 @@
package org.example;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import static org.junit.jupiter.api.Assertions.*;
class AdminTest {
@org.junit.jupiter.api.Test
void printAdminInfo() {
Admin admin = new Admin("Aaron", "A1001", "Admin");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(outputStream));
admin.printAdminInfo();
String printedOutput = outputStream.toString().trim();
assertTrue(printedOutput.contains("Aaron"));
assertTrue(printedOutput.contains("A1001"));
assertTrue(printedOutput.contains("Admin"));
}
}
Loading…
Cancel
Save