From c119b04864501bb9da39e020814d53414c7ef0fa Mon Sep 17 00:00:00 2001 From: WummerMIB Date: Tue, 8 Nov 2022 11:59:22 +0100 Subject: [PATCH] first test check second NullPointException dont now why --- .../informatik/bank/domain/Kunde.java | 31 +++++++++++---- .../informatik/bank/domain/KundeTest.java | 38 +++++++++++++++++++ 2 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/KundeTest.java diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Kunde.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Kunde.java index 208cb57..cda86d7 100644 --- a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Kunde.java +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/Kunde.java @@ -3,15 +3,15 @@ package de.hs_mannheim.informatik.bank.domain; import java.io.Serializable; import java.util.ArrayList; -public class Kunde implements Serializable{ - +public class Kunde implements Serializable { + private static int id = 0; private String vorname; private String name; private int alter; private String wohnort; private ArrayList konten; - + public Kunde(String vorname, String name, int alter, String wohnort) { this.vorname = vorname; this.name = name; @@ -19,22 +19,39 @@ public class Kunde implements Serializable{ this.wohnort = wohnort; this.id++; } - + + public String getVorname() { + return vorname; + } + + public String getName() { + return name; + } + + public int getAlter() { + return alter; + } + + public String getWohnort() { + return wohnort; + } + public void kundeHatKonte(Konto k) { konten.add(k); } - + public int getId() { return this.id; } - + public ArrayList getKonten() { return konten; } @Override public String toString() { - return "Vorname: " + this.vorname + " Name: " + this.name +" Alter: " + this.alter + " Wohnort: "+ this.wohnort; + return "Vorname: " + this.vorname + " Name: " + this.name + " Alter: " + this.alter + " Wohnort: " + + this.wohnort; } } diff --git a/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/KundeTest.java b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/KundeTest.java new file mode 100644 index 0000000..bf4a70f --- /dev/null +++ b/Bank-Beispiel/src/de/hs_mannheim/informatik/bank/domain/KundeTest.java @@ -0,0 +1,38 @@ +package de.hs_mannheim.informatik.bank.domain; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.ArrayList; + +import org.junit.jupiter.api.Test; + +class KundeTest { + + @Test + void testKontoBasic() { + Kunde k = new Kunde("TestVor","TestNam",20,"TestHeim"); + assertEquals(1, k.getId()); + assertEquals("TestVor", k.getVorname()); + assertEquals("TestNam", k.getName()); + assertEquals(20, k.getAlter()); + assertEquals("TestHeim", k.getWohnort()); + + } + + @Test + void testKundeHatKonto() { + Kunde ku = new Kunde("TestVor","TestNam",20,"TestHeim"); + Konto ko = new Konto("TestKonto",1); + Konto gi = new Girokonto("TestGiro",2); + Konto de = new Depot("Testdep",3); + ku.kundeHatKonte(ko); + ku.kundeHatKonte(gi); + ku.kundeHatKonte(de); + ArrayList konten = new ArrayList<>(); + konten.add(ko); + konten.add(gi); + konten.add(de); + assertTrue(konten.equals(ku.getKonten())); + } + +}