Created
February 5, 2016 14:00
-
-
Save gustavofranke/80b98d32852002cdf79a to your computer and use it in GitHub Desktop.
Singleton with Enum in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.junit.Test; | |
import static org.junit.Assert.*; | |
public class MyTest { | |
@Test | |
public void shouldReturnASDF() { | |
assertEquals("asdf", MySingleton.INSTANCE.asdf()); | |
} | |
@Test | |
public void shouldReturnQWER() { | |
assertEquals("qwer", MySingleton.INSTANCE.qwer()); | |
} | |
} | |
enum MySingleton { | |
INSTANCE; | |
private String asdf; | |
private String qwer; | |
MySingleton(){ | |
asdf = "asdf"; | |
qwer = "qwer"; | |
} | |
public String asdf(){ | |
return asdf; | |
} | |
public String qwer(){ | |
return qwer; | |
} | |
@Test | |
public void myTest() { | |
assertEquals("asdf", MySingleton.INSTANCE.asdf()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment