Can someone explain how my Junit passed successfully with below singleton implementation
EagerInitializations.java (singleton)
package com.r.patterns.design;
public class EagerInitializations {
private final String NAME="SINGELTON";
private static final EagerInitializations INSTANCE=CreateEagerInitializations();
private static EagerInitializations CreateEagerInitializations(){
System.out.println("step constructor");
return new EagerInitializations();
}
public final static EagerInitializations getInstance(){
System.out.println("step INSTANCE");
return INSTANCE;
}
public String getNAME() {
return NAME;
}
}
EagerInitializationsTest.java (JUnit test)
package com.r.patterns.design;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class EagerInitializationsTest {
@Test(expected = ClassNotFoundException.class)
public void testSingleton() throws ClassNotFoundException {
Class.forName("EagerInitializations");
EagerInitializations EI=null;
assertEquals(EI.getNAME(),new String("SINGELTON"));
}
}