title: Singleton Test with JUnit
body: <p>I have a singleton class like below :</p>
  
  <pre><code>  public enum SingletonClassA {
          INSTANCE;
  
          private final Map&lt;Character, Character&gt; characters;
  
          // private constructor
          SingletonClassA() {
              Map&lt;Character, Character&gt; aCharMap = new HashMap();
              aCharMap.put('a', 'e');
              aCharMap.put('o', 'u');
              // in order to keep short I erased other puts.
              characters = aCharMap;
          }
  
          public char getInstance(final char letter) {
              return characters.get(letter);
          }
  
          public boolean containsKey(char letter) {
              return characters.containsKey(letter);
          }
  
       }
  </code></pre>
  
  <p>And in order to test that I've create only one single object, even though I call more than once, I created a test case with JUnit : </p>
  
  <pre><code>public class SingletonTest {
      @Test
      public void TestSingletonObject(){
  
          SingletonClassA instance1 = SingletonClassA.INSTANCE;
          SingletonClassA instance2 = SingletonClassA.INSTANCE;
          //Passes
          Assert.assertSame("2 objects are same", instance1, instance2);
      }
  
      @Test
      public void TestgetInstance(){
  
          SingletonClassA instance1 = SingletonClassA.INSTANCE;
          SingletonClassA instance2 = SingletonClassA.INSTANCE;
          // Does not pass
          Assert.assertSame(instance1.getInstance('o'), instance2.getInstance('o'));
      }
  }
  </code></pre>
  
  <p>The test passes from TestSingletonObject() which says that those 2 objects are exactly the same. But from the second one, TestgetInstance(), it does not pass. </p>
  
  <hr>
  
  <p>My question is: why? Why it does not pass from the second test. I am thinking that even I call the instance methods it should return true because they belong to the exact same object. Am I missing a point?</p>