From 3f7c06bcff570513950858a94e3eac90069b2658 Mon Sep 17 00:00:00 2001 From: Tobias Herbert Date: Tue, 6 Feb 2024 21:28:57 +0100 Subject: [PATCH] Added Test to printAdminInfo Method from Admin Class --- pom.xml | 14 +++++++++++++ src/test/java/org/example/AdminTest.java | 26 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/test/java/org/example/AdminTest.java diff --git a/pom.xml b/pom.xml index 2d767b6..a8fb3e3 100644 --- a/pom.xml +++ b/pom.xml @@ -13,5 +13,19 @@ 19 UTF-8 + + + junit + junit + 4.13.1 + test + + + org.junit.jupiter + junit-jupiter + 5.8.1 + test + + \ No newline at end of file diff --git a/src/test/java/org/example/AdminTest.java b/src/test/java/org/example/AdminTest.java new file mode 100644 index 0000000..0c964fe --- /dev/null +++ b/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")); + + } +} \ No newline at end of file