Skip to content

Commit 24fe395

Browse files
authored
[engine] Add 'at most' and 'at least' aliases for comparison rules (#5726)
1 parent c914d69 commit 24fe395

File tree

4 files changed

+48
-11
lines changed

4 files changed

+48
-11
lines changed

docs/modules/parameters/pages/comparison-rule.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,44 @@ Shows how parameters should be compared.
66

77
== Possible values
88

9-
[cols="1,1,1", options="header"]
9+
[cols="1,1,1,1", options="header"]
1010
|===
1111

1212
|Plain
1313
|Readable
1414
|Mathematical
15+
|Alias
1516

1617
|LESS_THAN
1718
|less than
1819
|<
20+
|
1921

2022
|LESS_THAN_OR_EQUAL_TO
2123
|less than or equal to
2224
|
2325
+++
2426
<=
2527
+++
28+
|at most
2629

2730
|GREATER_THAN
2831
|greater than
2932
|>
33+
|
3034

3135
|GREATER_THAN_OR_EQUAL_TO
3236
|greater than or equal to
3337
|>=
38+
|at least
3439

3540
|EQUAL_TO
3641
|equal to
3742
|=
43+
|
3844

3945
|NOT_EQUAL_TO
4046
|not equal to
4147
|!=
48+
|
4249
|===

vividus-engine/src/main/java/org/vividus/steps/ComparisonRule.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2021 the original author or authors.
2+
* Copyright 2019-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,8 @@
1616

1717
package org.vividus.steps;
1818

19+
import java.util.Arrays;
20+
import java.util.List;
1921
import java.util.stream.Stream;
2022

2123
import org.hamcrest.Matcher;
@@ -32,7 +34,7 @@ public <T extends Comparable<T>> Matcher<T> getComparisonRule(T variable)
3234
return Matchers.lessThan(variable);
3335
}
3436
},
35-
LESS_THAN_OR_EQUAL_TO("<=")
37+
LESS_THAN_OR_EQUAL_TO("<=", "at most")
3638
{
3739
@Override
3840
public <T extends Comparable<T>> Matcher<T> getComparisonRule(T variable)
@@ -48,7 +50,7 @@ public <T extends Comparable<T>> Matcher<T> getComparisonRule(T variable)
4850
return Matchers.greaterThan(variable);
4951
}
5052
},
51-
GREATER_THAN_OR_EQUAL_TO(">=")
53+
GREATER_THAN_OR_EQUAL_TO(">=", "at least")
5254
{
5355
@Override
5456
public <T extends Comparable<T>> Matcher<T> getComparisonRule(T variable)
@@ -75,16 +77,19 @@ public <T extends Comparable<T>> Matcher<T> getComparisonRule(T variable)
7577
};
7678

7779
private final String sign;
80+
private final List<String> aliases;
7881

79-
ComparisonRule(String sign)
82+
ComparisonRule(String sign, String... aliases)
8083
{
8184
this.sign = sign;
85+
this.aliases = Arrays.asList(aliases);
8286
}
8387

8488
public static ComparisonRule fromString(String sign)
8589
{
8690
return Stream.of(values())
87-
.filter(comparisonRule -> sign.equalsIgnoreCase(comparisonRule.sign))
91+
.filter(comparisonRule -> sign.equalsIgnoreCase(comparisonRule.sign)
92+
|| comparisonRule.aliases.contains(sign.toLowerCase().replace('_', ' ')))
8893
.findFirst()
8994
.orElse(null);
9095
}

vividus-engine/src/test/java/org/vividus/steps/ComparisonRuleTests.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 the original author or authors.
2+
* Copyright 2019-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
3333
import org.junit.jupiter.params.ParameterizedTest;
3434
import org.junit.jupiter.params.provider.Arguments;
3535
import org.junit.jupiter.params.provider.MethodSource;
36+
import org.junit.jupiter.params.provider.ValueSource;
3637

3738
class ComparisonRuleTests
3839
{
@@ -80,13 +81,37 @@ static Stream<Arguments> getVariableMatcher()
8081
// @formatter:on
8182
}
8283

84+
static Stream<Arguments> getAliases()
85+
{
86+
// @formatter:off
87+
return Stream.of(
88+
Arguments.of("at most", ComparisonRule.LESS_THAN_OR_EQUAL_TO),
89+
Arguments.of("at least", ComparisonRule.GREATER_THAN_OR_EQUAL_TO)
90+
);
91+
// @formatter:on
92+
}
93+
8394
@ParameterizedTest
8495
@MethodSource("getComparisonRule")
8596
void comparisonRuleBySignTest(String sign, ComparisonRule rule)
8697
{
8798
assertEquals(rule, ComparisonRule.fromString(sign));
8899
}
89100

101+
@ParameterizedTest
102+
@ValueSource(strings = {"At Most", "AT_MOST", "AT MOST"})
103+
void comparisonRuleByAliasFormatTest(String alias)
104+
{
105+
assertEquals(ComparisonRule.LESS_THAN_OR_EQUAL_TO, ComparisonRule.fromString(alias));
106+
}
107+
108+
@ParameterizedTest
109+
@MethodSource("getAliases")
110+
void comparisonRuleByAliasTest(String alias, ComparisonRule rule)
111+
{
112+
assertEquals(rule, ComparisonRule.fromString(alias));
113+
}
114+
90115
@Test
91116
void comparisonRuleBySignEmptyOptionalTest()
92117
{
@@ -110,8 +135,8 @@ void shouldReturnEqualToMatcherForStringVariables()
110135

111136
@ParameterizedTest
112137
@MethodSource("getComparisonRuleAsString")
113-
void shouldReturnComparisonRulesInPlainText(String expecred, ComparisonRule toCheck)
138+
void shouldReturnComparisonRulesInPlainText(String expected, ComparisonRule toCheck)
114139
{
115-
assertEquals(expecred, toCheck.toString());
140+
assertEquals(expected, toCheck.toString());
116141
}
117142
}

vividus-tests/src/main/resources/story/integration/DynamicVariablesTests.story

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Then `${rect.height}` is = `400`
2626
Then `${rect.width}` is = `400`
2727
!-- Browser window has borders of 8px size on Windows OS, that's why x == 192 on Windows and x == 200 on Linux and MacOS
2828
!-- https://stackoverflow.com/a/42491227/2067574
29-
Then `${rect.x}` is >= `192`
30-
Then `${rect.x}` is <= `200`
29+
Then `${rect.x}` is at least `192`
30+
Then `${rect.x}` is at most `200`
3131
Then `${rect.y}` is = `8`
3232

3333
Scenario: Verify `source-code` dynamic variable

0 commit comments

Comments
 (0)