### Question:
CodeExpression implements Serializable { public static synchronized CodeExpression valueOf(String expression, Code code) { numValueOfs++; HashMap<String, CodeExpression> allExpressions; switch (code) { case JAVA: allExpressions = javaExpressions; break; case SPICE: allExpressions = spiceExpressions; break; case TCL: allExpressions = tclExpressions; break; default: throw new IllegalArgumentException("code"); } CodeExpression ce = allExpressions.get(expression); if (ce == null) { ce = new CodeExpression(expression, code); allExpressions.put(expression, ce); } return ce; } private  CodeExpression(String expr, Code code); static synchronized CodeExpression valueOf(String expression, Code code); Code getCode(); boolean isJava(); String getExpr(); Set<Variable.Key> dependsOn(); EvalSpice.ParseException getParseException(); String getSpiceText(); String getHSpiceText(boolean inPar); String getVerilogText(); Object eval(); @Override int hashCode(); @Override boolean equals(Object o); @Override String toString(); void write(IdWriter writer); static CodeExpression read(IdReader reader); static void printStatistics(boolean verbose);  }### Answer:
@Test public void valueOf() { System.out.println("valueOf"); CodeExpression ja = CodeExpression.valueOf("a", CodeExpression.Code.JAVA); assertSame(CodeExpression.Code.JAVA, ja.getCode()); assertTrue(ja.isJava()); assertEquals("a", ja.getExpr()); CodeExpression sa = CodeExpression.valueOf("a", CodeExpression.Code.SPICE); assertSame(CodeExpression.Code.SPICE, sa.getCode()); assertFalse(sa.isJava()); assertEquals("a", sa.getExpr()); CodeExpression ta = CodeExpression.valueOf("a", CodeExpression.Code.TCL); assertSame(CodeExpression.Code.TCL, ta.getCode()); assertFalse(sa.isJava()); assertEquals("a", sa.getExpr()); CodeExpression ja1 = CodeExpression.valueOf("a", CodeExpression.Code.JAVA); assertSame(ja, ja1); CodeExpression sa1 = CodeExpression.valueOf("a", CodeExpression.Code.SPICE); assertSame(sa, sa1); CodeExpression ta1 = CodeExpression.valueOf("a", CodeExpression.Code.TCL); assertSame(ta, ta1); }
@Test(expected = NullPointerException.class) public void valueOfNullCode() { System.out.println("valueOfNullCode"); CodeExpression.valueOf("a", null); }
@Test(expected = IllegalArgumentException.class) public void valueOfBadCode() { System.out.println("valueOfBadCode"); CodeExpression.valueOf("a", CodeExpression.Code.NONE); }