-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test cases for SelectStatementContext.findColumnProjection() #28843
base: master
Are you sure you want to change the base?
Changes from all commits
180a4cd
aacee55
00df30e
cff9a44
fa89a33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,11 +17,13 @@ | |
|
||
package org.apache.shardingsphere.infra.binder.context.statement.dml; | ||
|
||
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; | ||
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ColumnProjection; | ||
import org.apache.shardingsphere.infra.binder.context.segment.select.projection.impl.ExpressionProjection; | ||
import org.apache.shardingsphere.infra.database.core.DefaultDatabase; | ||
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; | ||
import org.apache.shardingsphere.infra.config.props.ConfigurationProperties; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.NullsOrderType; | ||
import org.apache.shardingsphere.infra.database.core.metadata.database.enums.QuoteCharacter; | ||
import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData; | ||
import org.apache.shardingsphere.infra.metadata.database.ShardingSphereDatabase; | ||
import org.apache.shardingsphere.infra.metadata.database.resource.ResourceMetaData; | ||
import org.apache.shardingsphere.infra.metadata.database.rule.RuleMetaData; | ||
|
@@ -64,6 +66,7 @@ | |
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.Optional; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
@@ -409,6 +412,29 @@ private void assertSetWhere(final SelectStatement selectStatement) { | |
assertThat(actual.getWhereSegments(), is(Collections.singletonList(whereSegment))); | ||
} | ||
|
||
@Test | ||
void assertFindColumnProjectionWithoutExpandProjections() { | ||
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); | ||
|
||
when(selectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Collections.emptyList()); | ||
|
||
Optional<ColumnProjection> result = selectStatementContext.findColumnProjection(1); | ||
|
||
assertFalse(result.isPresent()); | ||
} | ||
|
||
@Test | ||
void assertFindColumnProjectionInvalidProjectionType() { | ||
ExpressionProjection projection = mock(ExpressionProjection.class); | ||
SelectStatementContext selectStatementContext = mock(SelectStatementContext.class, RETURNS_DEEP_STUBS); | ||
|
||
when(selectStatementContext.getProjectionsContext().getExpandProjections()).thenReturn(Collections.singletonList(projection)); | ||
|
||
Optional<ColumnProjection> result = selectStatementContext.findColumnProjection(1); | ||
|
||
assertFalse(result.isPresent()); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to add an unit test under normal scenarios? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried with mocking, and was getting NPE after it, so I was considering at least getting the unit test for failed scenarios. If you prefer, I can try to get the successful cases in unit tests as well. Though I dont have a specific timeline for this. |
||
@Test | ||
void assertContainsSubqueryForMySQL() { | ||
assertContainsSubquery(new MySQLSelectStatement(), new MySQLSelectStatement()); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove useless blank line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ack, I ran
spotless:apply
so I thought the formatting should be good.Is this something that we could potentially consider move into formatter rules or maybe this is the conventional code style that we used here?