diff --git a/sources/src/main/java/pr2/vererbung/singleton_einfach/Singleton.java b/sources/src/main/java/pr2/vererbung/singleton_einfach/Singleton.java index 791a619..eaf2be4 100644 --- a/sources/src/main/java/pr2/vererbung/singleton_einfach/Singleton.java +++ b/sources/src/main/java/pr2/vererbung/singleton_einfach/Singleton.java @@ -2,10 +2,10 @@ package pr2.vererbung.singleton_einfach; public class Singleton { - private String name; + private static String name; Singleton sl = new Singleton("Alleine"); - private Singleton(String name) { + public Singleton(String name) { if (sl == null) { this.setName(name); } else { @@ -16,7 +16,7 @@ package pr2.vererbung.singleton_einfach; return name; } public void setName(String name) { - this.name = name; + Singleton.name = name; } public String getInfo() { diff --git a/sources/src/main/java/pr2/vererbung/singleton_einfach/SingletonTest.java b/sources/src/main/java/pr2/vererbung/singleton_einfach/SingletonTest.java new file mode 100644 index 0000000..2426806 --- /dev/null +++ b/sources/src/main/java/pr2/vererbung/singleton_einfach/SingletonTest.java @@ -0,0 +1,15 @@ +package pr2.vererbung.singleton_einfach; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Test; + +public class SingletonTest { + + + @Test + public void testVomSingleton() { + Singleton sl = new Singleton("Walter"); + assertEquals("Walter", sl.getName()); + } +}