BlockingObject { public static Object getBlockingObject (String key) { StackTraceElement ste = Thread.currentThread ().getStackTrace ()[2]; StringBuilder sb = new StringBuilder (); sb.append (ste.getClassName ()).append (":"); sb.append (ste.getMethodName ()).append (":"); sb.append (key); return sb.toString ().intern (); }  static Object getBlockingObject(String key);  }
@Test public void testGetBlockingObject () { String key1 = "testEquals"; String key2 = "testEquals"; String key3 = "testNotEquals"; Object obj1 = BlockingObject.getBlockingObject (key1); Object obj2 = BlockingObject.getBlockingObject (key2); Object obj3 = BlockingObject.getBlockingObject (key3); if (obj1 instanceof String) { String methodName = "testGetBlockingObject"; String expected = getClass ().getName () + ":" +methodName + ":" + key1; Assert.assertEquals (obj1.toString (), expected); } if (obj1 != obj2) { Assert.fail ("obj1 and obj2 should be the same !"); } if (obj1 == obj3) { Assert.fail ("obj1 and obj2 should not be the same !"); } }