Test fuer Singleton???

kleinerRech
Kai Sellmann 2023-05-29 20:26:32 +02:00
parent bc7476966d
commit 8e305277a7
2 changed files with 18 additions and 3 deletions

View File

@ -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() {

View File

@ -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());
}
}