-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…1603) * [ISSUE #21569] Add Tests for ShardingAutoTableAlgorithmUtil Class * [ISSUE #21569] Fix checkstyle errors * [ISSUE #21569] Change the ShardingAutoTableAlgorithmUtilTest class as final * [ISSUE #21569] remove empty spaces and final modifier for method variables * [ISSUE #21569] Change assertEquals to assertThat in tests Co-authored-by: Karthick B <[email protected]>
- Loading branch information
1 parent
06f5dd7
commit 8848cfa
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
...apache/shardingsphere/sharding/algorithm/sharding/ShardingAutoTableAlgorithmUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.shardingsphere.sharding.algorithm.sharding; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertThat; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Optional; | ||
import org.apache.shardingsphere.infra.datanode.DataNodeInfo; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public final class ShardingAutoTableAlgorithmUtilTest { | ||
|
||
private Collection<String> collection; | ||
|
||
private DataNodeInfo dataNodeInfo; | ||
|
||
@Before | ||
public void setup() { | ||
collection = new ArrayList<>(); | ||
collection.add("PREFIX----SUFFIX"); | ||
collection.add("PREFIXSUFFIXSTRING"); | ||
collection.add("PREFIX----------"); | ||
String prefix = "PREFIX"; | ||
int suffixMinLength = 10; | ||
char paddingChar = '-'; | ||
dataNodeInfo = new DataNodeInfo(prefix, suffixMinLength, paddingChar); | ||
} | ||
|
||
@Test | ||
public void assertFindMatchedTargetNameForValidInputs() { | ||
Optional<String> output = ShardingAutoTableAlgorithmUtil.findMatchedTargetName(collection, "SUFFIX", dataNodeInfo); | ||
assertTrue(output.isPresent()); | ||
assertThat("PREFIX----SUFFIX", is(output.get())); | ||
Optional<String> output1 = ShardingAutoTableAlgorithmUtil.findMatchedTargetName(collection, "SUFFIXSTRING", dataNodeInfo); | ||
assertTrue(output1.isPresent()); | ||
assertThat("PREFIXSUFFIXSTRING", is(output1.get())); | ||
Optional<String> output2 = ShardingAutoTableAlgorithmUtil.findMatchedTargetName(collection, "", dataNodeInfo); | ||
assertTrue(output2.isPresent()); | ||
assertThat("PREFIX----------", is(output2.get())); | ||
} | ||
|
||
@Test | ||
public void assertFindMatchedTargetNameNonExistingInput() { | ||
Optional<String> output = ShardingAutoTableAlgorithmUtil.findMatchedTargetName(collection, "NONEXISTINGSUFFIX", dataNodeInfo); | ||
assertFalse(output.isPresent()); | ||
} | ||
} |