Skip to content

Commit

Permalink
Add more test cases on OrderByToken (#33685)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Nov 16, 2024
1 parent abbf473 commit fa4e76d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public OrderByToken(final int startIndex) {
super(startIndex);
}

@Override
public int getStopIndex() {
return getStartIndex();
}

@Override
public String toString() {
StringBuilder result = new StringBuilder();
Expand All @@ -53,9 +58,4 @@ public String toString() {
result.append(' ');
return result.toString();
}

@Override
public int getStopIndex() {
return getStartIndex();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,29 @@
package org.apache.shardingsphere.sharding.rewrite.token.pojo;

import org.apache.shardingsphere.sql.parser.statement.core.enums.OrderDirection;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

class OrderByTokenTest {

private OrderByToken orderByToken;

@BeforeEach
void setup() {
orderByToken = new OrderByToken(0);
List<String> columnLabels = orderByToken.getColumnLabels();
List<OrderDirection> orderDirections = orderByToken.getOrderDirections();
columnLabels.add(0, "Test1");
columnLabels.add(1, "Test2");
orderDirections.add(0, OrderDirection.ASC);
orderDirections.add(1, OrderDirection.ASC);
@Test
void assertGetStopIndex() {
assertThat(new OrderByToken(10).getStopIndex(), is(10));
}

@Test
void assertToString() {
assertThat(orderByToken.toString(), is(" ORDER BY Test1 ASC,Test2 ASC "));
assertThat(createOrderByToken().toString(), is(" ORDER BY foo_col ASC,bar_col ASC "));
}

private OrderByToken createOrderByToken() {
OrderByToken result = new OrderByToken(0);
result.getColumnLabels().add(0, "foo_col");
result.getColumnLabels().add(1, "bar_col");
result.getOrderDirections().add(0, OrderDirection.ASC);
result.getOrderDirections().add(1, OrderDirection.ASC);
return result;
}
}

0 comments on commit fa4e76d

Please sign in to comment.