Skip to content

Commit

Permalink
Merge pull request #75 from Julius278/feature/325-tradeID-fix
Browse files Browse the repository at this point in the history
SDC-325, tradeID using hyphen instead of underscore
  • Loading branch information
cfries authored Jul 23, 2024
2 parents 034c5cc + c93a42c commit 18c2967
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ jobs:
name: Java 17 build and unit testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Java
uses: actions/setup-java@v1
uses: actions/setup-java@v2
with:
distribution: 'zulu'
java-version: 17
- name: Build with Maven
run: mvn -B package --file pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ private TradeUtils(){}
*/
public static String getUniqueTradeId(){
String uniqueID = UUID.randomUUID().toString().replace("-", "").substring(0, 17);
return "ID_" + uniqueID;
return "ID-" + uniqueID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ class TradeUtilsTest {

@Test
void getUniqueTradeId() {
String idPrefix = "ID-";
List<String> ids = new ArrayList<>();
for (int i = 1; i <= 200 ; i++){
for (int i = 1; i <= 200; i++) {
String id = TradeUtils.getUniqueTradeId();
System.out.println(i + ". " +id);
assertTrue(id.contains("ID_"));
System.out.println(i + ". " + id);
assertTrue(id.contains(idPrefix));

//max length 20
assertEquals(20, id.length());

//id only contains letters and numbers (and the leading underscore)
assertTrue(Pattern.matches("ID_[a-zA-Z0-9]+", id));
assertTrue(Pattern.matches(idPrefix + "[a-zA-Z0-9]+", id));

//check on uniqueness
assertFalse(ids.contains(id));
Expand Down

0 comments on commit 18c2967

Please sign in to comment.