This is an automated email from the ASF dual-hosted git repository.
zhangliang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new e6d5743ffa5 Add more test cases on ShorthandProjection (#33196)
e6d5743ffa5 is described below
commit e6d5743ffa5bd6df4075134ffb458c0e4af85405
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Oct 9 23:21:59 2024 +0800
Add more test cases on ShorthandProjection (#33196)
---
.../projection/impl/ShorthandProjection.java | 40 +++++++++++-----------
.../projection/impl/ShorthandProjectionTest.java | 35 +++++++++++++++----
2 files changed, 49 insertions(+), 26 deletions(-)
diff --git
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ShorthandProjection.java
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ShorthandProjection.java
index 82f6d5a8b62..3e3424c52e7 100644
---
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ShorthandProjection.java
+++
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ShorthandProjection.java
@@ -41,26 +41,6 @@ public final class ShorthandProjection implements Projection
{
private final Collection<Projection> actualColumns;
- @Override
- public String getColumnName() {
- return null == owner ? "*" : owner.getValue() + ".*";
- }
-
- @Override
- public String getColumnLabel() {
- return "*";
- }
-
- @Override
- public String getExpression() {
- return null == owner ? "*" : owner.getValue() + ".*";
- }
-
- @Override
- public Optional<IdentifierValue> getAlias() {
- return Optional.empty();
- }
-
/**
* Get owner.
*
@@ -84,4 +64,24 @@ public final class ShorthandProjection implements Projection
{
}
return result;
}
+
+ @Override
+ public String getColumnName() {
+ return null == owner ? "*" : owner.getValue() + ".*";
+ }
+
+ @Override
+ public String getColumnLabel() {
+ return "*";
+ }
+
+ @Override
+ public String getExpression() {
+ return null == owner ? "*" : owner.getValue() + ".*";
+ }
+
+ @Override
+ public Optional<IdentifierValue> getAlias() {
+ return Optional.empty();
+ }
}
diff --git
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ShorthandProjectionTest.java
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ShorthandProjectionTest.java
index 17a3bbb5a34..c187e95a014 100644
---
a/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ShorthandProjectionTest.java
+++
b/infra/binder/src/test/java/org/apache/shardingsphere/infra/binder/context/segment/select/projection/impl/ShorthandProjectionTest.java
@@ -17,26 +17,39 @@
package
org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl;
+import
org.apache.shardingsphere.infra.binder.context.segment.select.projection.Projection;
import
org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
import org.junit.jupiter.api.Test;
+import java.util.Arrays;
import java.util.Collections;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
class ShorthandProjectionTest {
@Test
- void assertGetExpression() {
- assertThat(new ShorthandProjection(new IdentifierValue("owner"),
Collections.emptyList()).getExpression(), is("owner.*"));
+ void assertGetOwner() {
+ assertTrue(new ShorthandProjection(new IdentifierValue("owner"),
Collections.emptyList()).getOwner().isPresent());
}
@Test
- void assertGetAliasWhenAbsent() {
- assertFalse(new ShorthandProjection(new IdentifierValue("owner"),
Collections.emptyList()).getAlias().isPresent());
+ void assertGetColumnNameWithOwner() {
+ assertThat(new ShorthandProjection(new IdentifierValue("owner"),
Collections.emptyList()).getColumnName(), is("owner.*"));
+ }
+
+ @Test
+ void assertGetColumnNameWithoutOwner() {
+ assertThat(new ShorthandProjection(null,
Collections.emptyList()).getColumnName(), is("*"));
+ }
+
+ @Test
+ void assertGetColumnProjections() {
+ assertThat(new ShorthandProjection(new IdentifierValue("owner"),
Arrays.asList(mock(Projection.class),
mock(ColumnProjection.class))).getColumnProjections().size(), is(1));
}
@Test
@@ -45,7 +58,17 @@ class ShorthandProjectionTest {
}
@Test
- void assertContains() {
- assertTrue(new ShorthandProjection(new IdentifierValue("owner"),
Collections.emptyList()).getOwner().isPresent());
+ void assertGetExpressionWithOwner() {
+ assertThat(new ShorthandProjection(new IdentifierValue("owner"),
Collections.emptyList()).getExpression(), is("owner.*"));
+ }
+
+ @Test
+ void assertGetExpressionWithoutOwner() {
+ assertThat(new ShorthandProjection(null,
Collections.emptyList()).getExpression(), is("*"));
+ }
+
+ @Test
+ void assertGetAlias() {
+ assertFalse(new ShorthandProjection(new IdentifierValue("owner"),
Collections.emptyList()).getAlias().isPresent());
}
}