TableNameOrderByComparator extends OrderByComparator<T> { @Override public String getOrderBy() { String orderBy = _orderByComparator.getOrderBy(); if (_tableName == null) { return orderBy; } String[] columnNames = StringUtil.split(orderBy); StringBundler sb = new StringBundler((3 * columnNames.length) - 1); for (int i = 0; i < columnNames.length; ++i) { String columnName = columnNames[i]; if (columnName.indexOf(CharPool.PERIOD) != -1) { columnName = StringUtil.split(columnName, CharPool.PERIOD)[1]; } sb.append(_tableName); sb.append(StringUtil.trim(columnName)); if (i < (columnNames.length - 1)) { sb.append(StringPool.COMMA_AND_SPACE); } } return sb.toString(); } TableNameOrderByComparator(
		OrderByComparator<T> orderByComparator, String tableName); @Override int compare(T obj1, T obj2); @Override String getOrderBy(); @Override String[] getOrderByConditionFields(); @Override Object[] getOrderByConditionValues(Object obj); @Override String[] getOrderByFields(); OrderByComparator<T> getWrappedOrderByComparator(); @Override boolean isAscending(); @Override boolean isAscending(String field); void setTableName(String tableName); @Override String toString();  }
@Test public void testGetOrderByTableNameWithPeriodReturnsDecoratedTableName() { TableNameOrderByComparator<?> tableNameOrderByComparator = new TableNameOrderByComparator<>( new TestGetOrderByComparator("column"), "table."); Assert.assertEquals( "table.column", tableNameOrderByComparator.getOrderBy()); }
@Test public void testGetOrderByWithBlankTableNameReturnsUndecoratedTableName() { TableNameOrderByComparator<?> tableNameOrderByComparator = new TableNameOrderByComparator<>( new TestGetOrderByComparator("column1, column2"), ""); Assert.assertEquals( "column1, column2", tableNameOrderByComparator.getOrderBy()); }
@Test public void testGetOrderByWithMultipleColumnNamesReturnsDecoratedTableName() { TableNameOrderByComparator<?> tableNameOrderByComparator = new TableNameOrderByComparator<>( new TestGetOrderByComparator("column1, column2"), "table"); Assert.assertEquals( "table.column1, table.column2", tableNameOrderByComparator.getOrderBy()); }
@Test public void testGetOrderByWithMultipleTableNameReturnsNewTableName() { TableNameOrderByComparator<?> tableNameOrderByComparator = new TableNameOrderByComparator<Object>( new TestGetOrderByComparator("table1.column1, column2"), "table2"); Assert.assertEquals( "table2.column1, table2.column2", tableNameOrderByComparator.getOrderBy()); }
@Test public void testGetOrderByWithNullTableNameReturnsUndecoratedTableName() { TableNameOrderByComparator<?> tableNameOrderByComparator = new TableNameOrderByComparator<>( new TestGetOrderByComparator("column1, column2"), null); Assert.assertEquals( "column1, column2", tableNameOrderByComparator.getOrderBy()); }
@Test public void testGetOrderByWithSingleColumnNameReturnsDecoratedTableName() { TableNameOrderByComparator<?> tableNameOrderByComparator = new TableNameOrderByComparator<>( new TestGetOrderByComparator("column"), "table"); Assert.assertEquals( "table.column", tableNameOrderByComparator.getOrderBy()); }
@Test public void testGetOrderByWithSingleTableNameReturnsNewTableName() { TableNameOrderByComparator<?> tableNameOrderByComparator = new TableNameOrderByComparator<>( new TestGetOrderByComparator("table1.column1"), "table2"); Assert.assertEquals( "table2.column1", tableNameOrderByComparator.getOrderBy()); }
@Test public void testGetOrderByWithSortDirectionReturnsDecoratedTableName() { TableNameOrderByComparator<?> tableNameOrderByComparator = new TableNameOrderByComparator<>( new TestGetOrderByComparator("column ASC"), "table"); Assert.assertEquals( "table.column ASC", tableNameOrderByComparator.getOrderBy()); }