Table { String name() { SQLExpr expr = tableExpr.getExpr(); if (expr instanceof SQLIdentifierExpr) { return ((SQLIdentifierExpr) expr).getName(); } else if (isTableWithType(expr)) { return ((SQLIdentifierExpr) ((SQLBinaryOpExpr) expr).getLeft()).getName(); } return expr.toString(); } Table(SQLExprTableSource tableExpr);   }
@Test public void identifierOfTableNameShouldReturnTheTableName() { Table table = new Table(new SQLExprTableSource(new SQLIdentifierExpr("accounts"))); Assert.assertEquals("accounts", table.name()); }
@Test public void identifierOfTableAndTypeNameShouldReturnTheTableNameOnly() { Table table = new Table(new SQLExprTableSource( new SQLBinaryOpExpr( new SQLIdentifierExpr("accounts"), SQLBinaryOperator.Divide, new SQLIdentifierExpr("test") ) )); Assert.assertEquals("accounts", table.name()); }