You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2019/10/09 04:57:35 UTC

[GitHub] [incubator-shardingsphere] terrymanu commented on a change in pull request #3186: improved coverage for package of preprocessor

terrymanu commented on a change in pull request #3186:  improved coverage for package of preprocessor
URL: https://github.com/apache/incubator-shardingsphere/pull/3186#discussion_r332829103
 
 

 ##########
 File path: sharding-core/sharding-core-preprocessor/src/test/java/org/apache/shardingsphere/core/optimize/segment/table/TablesContextTest.java
 ##########
 @@ -133,6 +138,50 @@ public void assertNotFoundTable() {
         assertFalse(table.isPresent());
     }
     
+    @Test
+    public void assertFindTableNameWhenSingleTable() {
+        SelectStatement selectStatement = new SelectStatement();
+        selectStatement.getAllSQLSegments().add(createTableSegment("table_1", "tbl_1"));
+        assertTrue(new TablesContext(selectStatement).findTableName(null, null).isPresent());
+    }
+    
+    @Test
+    public void assertFindTableNameWhenColumnSegmentOwnerPresent() {
+        SelectStatement selectStatement = new SelectStatement();
+        selectStatement.getAllSQLSegments().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getAllSQLSegments().add(createTableSegment("table_2", "tbl_2"));
+        TablesContext tablesContext = new TablesContext(selectStatement);
+        ColumnSegment columnSegment = mock(ColumnSegment.class);
+        when(columnSegment.getOwner()).thenReturn(Optional.of(new TableSegment(0, 10, "table_1")));
+        assertTrue(tablesContext.findTableName(columnSegment, null).isPresent());
+    }
+    
+    @Test
+    public void assertFindTableNameWhenColumnSegmentOwnerAbsent() {
+        SelectStatement selectStatement = new SelectStatement();
+        selectStatement.getAllSQLSegments().add(createTableSegment("table_1", "tbl_1"));
+        selectStatement.getAllSQLSegments().add(createTableSegment("table_2", "tbl_2"));
+        TablesContext tablesContext = new TablesContext(selectStatement);
+        ColumnSegment columnSegment = mock(ColumnSegment.class);
+        when(columnSegment.getOwner()).thenReturn(Optional.<TableSegment>absent());
+        TableMetas tableMetas = mock(TableMetas.class);
+        when(tableMetas.containsColumn(anyString(), anyString())).thenReturn(false);
 
 Review comment:
   Can you have a try for remove this line? mock result with false is default action, maybe we do not need to mock it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services