Test fuer Singleton???
parent
bc7476966d
commit
8e305277a7
|
@ -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() {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue