### Question:
Symbol { @Override public String toString() { return toString(false); } Symbol();  Symbol(String name, SymbolType type, int tableIndex); Group getGroup(); String getName(); SymbolType getType(); int getTableIndex(); void setGroup(Group group); void setName(String name); void setType(SymbolType type); void setTableIndex(int tableIndex); @Override String toString(); String toString(boolean alwaysDelimitTerminals);  }### Answer:
@Test public void testToString() { int index = 0; for (SymbolType symbolType : SymbolType.values()) { index++; String name = "Symbol" + index; String expected; if (symbolType.equals(SymbolType.CONTENT)) { expected = "'" + name + "'"; } else if (symbolType.equals(SymbolType.NON_TERMINAL)) { expected = "<" + name + ">"; } else { expected = "(" + name + ")"; } Symbol symbol = new Symbol(name, symbolType, index); assertEquals("wrong text", expected, symbol.toString()); } }
@Test public void testToStringEscapingName() { Symbol symbol = new Symbol("SymbolName", null, 1); assertEquals("wrong text", "<not initialized>", symbol.toString(true)); assertEquals("wrong text", "<not initialized>", symbol.toString(false)); symbol = new Symbol(null, SymbolType.CONTENT, 1); assertEquals("wrong text", "null", symbol.toString(true)); assertEquals("wrong text", "null", symbol.toString(false)); symbol = new Symbol("SymbolName", SymbolType.CONTENT, 1); assertEquals("wrong text", "'SymbolName'", symbol.toString(true)); assertEquals("wrong text", "SymbolName", symbol.toString(false)); symbol = new Symbol("Symbol.Name", SymbolType.CONTENT, 1); assertEquals("wrong text", "'Symbol.Name'", symbol.toString(true)); assertEquals("wrong text", "Symbol.Name", symbol.toString(false)); symbol = new Symbol("Symbol_Name", SymbolType.CONTENT, 1); assertEquals("wrong text", "'Symbol_Name'", symbol.toString(true)); assertEquals("wrong text", "Symbol_Name", symbol.toString(false)); symbol = new Symbol("'", SymbolType.CONTENT, 1); assertEquals("wrong text", "''", symbol.toString(true)); assertEquals("wrong text", "''", symbol.toString(false)); symbol = new Symbol("Symbol*Name", SymbolType.CONTENT, 1); assertEquals("wrong text", "'Symbol*Name'", symbol.toString(true)); assertEquals("wrong text", "'Symbol*Name'", symbol.toString(false)); }
@Test public void testToStringNotEscapingStandaloneSymbolsThatCouldBeInName() { Symbol symbol = new Symbol(".", SymbolType.CONTENT, 1); assertEquals("wrong text", "'.'", symbol.toString(true)); assertEquals("wrong text", "'.'", symbol.toString(false)); symbol = new Symbol("-", SymbolType.CONTENT, 1); assertEquals("wrong text", "'-'", symbol.toString(true)); assertEquals("wrong text", "'-'", symbol.toString(false)); symbol = new Symbol("_", SymbolType.CONTENT, 1); assertEquals("wrong text", "'_'", symbol.toString(true)); assertEquals("wrong text", "'_'", symbol.toString(false)); }