terrymanu commented on a change in pull request #3205: bugfix for #3144
URL: 
https://github.com/apache/incubator-shardingsphere/pull/3205#discussion_r333382067
 
 

 ##########
 File path: 
sharding-core/sharding-core-route/src/test/java/org/apache/shardingsphere/core/route/router/sharding/validator/impl/ShardingUpdateStatementValidatorTest.java
 ##########
 @@ -30,32 +41,79 @@
 import org.mockito.Mock;
 import org.mockito.junit.MockitoJUnitRunner;
 
-import java.util.Collections;
-
-import static org.mockito.Mockito.when;
+import com.google.common.collect.Lists;
 
 @RunWith(MockitoJUnitRunner.class)
 public final class ShardingUpdateStatementValidatorTest {
-    
+
     @Mock
     private ShardingRule shardingRule;
-    
+
     @Test
     public void assertValidateUpdateWithoutShardingKey() {
         when(shardingRule.isShardingColumn("id", "user")).thenReturn(false);
-        new ShardingUpdateStatementValidator().validate(shardingRule, 
createUpdateStatement());
+        new ShardingUpdateStatementValidator().validate(shardingRule, 
createUpdateStatement(), null);
     }
-    
+
     @Test(expected = ShardingException.class)
     public void assertValidateUpdateWithShardingKey() {
         when(shardingRule.isShardingColumn("id", "user")).thenReturn(true);
-        new ShardingUpdateStatementValidator().validate(shardingRule, 
createUpdateStatement());
+        new ShardingUpdateStatementValidator().validate(shardingRule, 
createUpdateStatement(), null);
     }
-    
+
+    @Test
+    public void assertValidateUpdateWithoutShardingKeyAndParameters() {
+        when(shardingRule.isShardingColumn("id", "user")).thenReturn(false);
+        List<Object> parameters = Lists.newArrayList();
+        parameters.add(1);
+        parameters.add(1);
+        new ShardingUpdateStatementValidator().validate(shardingRule, 
createUpdateStatementAndParameters(1), parameters);
+    }
+
+    @Test
+    public void 
assertValidateUpdateWithShardingKeyAndShardingParameterEquals() {
+        when(shardingRule.isShardingColumn("id", "user")).thenReturn(true);
+        List<Object> parameters = Lists.newArrayList();
+        parameters.add(1);
+        parameters.add(1);
+        // set parameter = 1
+        // where patameter = 2
+        new ShardingUpdateStatementValidator().validate(shardingRule, 
createUpdateStatementAndParameters(1), parameters);
+    }
+
+    @Test(expected = ShardingException.class)
+    public void 
assertValidateUpdateWithShardingKeyAndShardingParameterNotEquals() {
+        when(shardingRule.isShardingColumn("id", "user")).thenReturn(true);
+        List<Object> parameters = Lists.newArrayList();
+        parameters.add(1);
+        parameters.add(1);
+        // set parameter = 1
+        // where patameter = 2
+        new ShardingUpdateStatementValidator().validate(shardingRule, 
createUpdateStatementAndParameters(2), parameters);
+    }
+
     private UpdateStatement createUpdateStatement() {
         UpdateStatement result = new UpdateStatement();
         result.getAllSQLSegments().add(new TableSegment(0, 0, "user"));
         result.setSetAssignment(new SetAssignmentsSegment(0, 0, 
Collections.singletonList(new AssignmentSegment(0, 0, new ColumnSegment(0, 0, 
"id"), new LiteralExpressionSegment(0, 0, "")))));
         return result;
     }
+
+    private UpdateStatement createUpdateStatementAndParameters(final Object 
shardingColumnPatamater) {
+        UpdateStatement result = new UpdateStatement();
+        result.getAllSQLSegments().add(new TableSegment(0, 0, "user"));
+        // set shardingColumnPatamater
+        Collection<AssignmentSegment> assignments = 
Collections.singletonList(new AssignmentSegment(0, 0, new ColumnSegment(0, 0, 
"id"), new LiteralExpressionSegment(0, 0, shardingColumnPatamater)));
+        SetAssignmentsSegment setAssignmentsSegment = new 
SetAssignmentsSegment(0, 0, assignments);
+        result.setSetAssignment(setAssignmentsSegment);
+
 
 Review comment:
   please remove useless blank line

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to