Skip to content

Commit 895dca1

Browse files
committed
cleaning code
1 parent 495332f commit 895dca1

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

client/src/test/java/io/split/engine/evaluator/EvaluatorTest.java

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package io.split.engine.evaluator;
22

3-
import io.split.client.*;
3+
import io.split.client.EventClient;
4+
import io.split.client.SplitClientConfig;
5+
import io.split.client.SplitClientImpl;
6+
import io.split.client.SplitFactory;
47
import io.split.client.dtos.ConditionType;
58
import io.split.client.dtos.Partition;
69
import io.split.client.dtos.TreatmentLabelAndChangeNumber;
@@ -24,26 +27,29 @@
2427
import static org.junit.Assert.assertEquals;
2528

2629
public class EvaluatorTest {
30+
private static final String _matchingKey = "test";
31+
private static final String _bucketingKey = "test";
32+
private static final String _splitName = "split_name_test";
33+
private static final Long _changeNumber = 123123L;
34+
private static final String _defaultTreatmentValue = "defaultTreatment";
35+
private static final String _testLabelValue = "test label";
36+
private static final String _trafficTypeValue = "tt";
37+
private static final String _treatmentValue = "treatment_test";
38+
2739
private SplitFetcher _splitFetcher;
28-
private SDKReadinessGates _gates;
2940
private Evaluator _evaluator;
3041
private SplitClientImpl _splitClient;
3142
private CombiningMatcher _matcher;
3243
private Map<String, String> _configurations;
3344
private List<ParsedCondition> _conditions;
3445
private List<Partition> _partitions;
3546

36-
private String _matchingKey = "test";
37-
private String _bucketingKey = "test";
38-
private String _splitName = "split_name_test";
39-
private Long _changeNumber = 123123L;
40-
4147
@Before
4248
public void before() {
49+
SDKReadinessGates gates = Mockito.mock(SDKReadinessGates.class);
4350
_splitFetcher = Mockito.mock(SplitFetcher.class);
44-
_gates = Mockito.mock(SDKReadinessGates.class);
45-
_evaluator = new EvaluatorImp(_gates, _splitFetcher);
46-
_splitClient = getSplitClient(_splitFetcher, _gates, _evaluator);
51+
_evaluator = new EvaluatorImp(gates, _splitFetcher);
52+
_splitClient = getSplitClient(_splitFetcher, gates, _evaluator);
4753
_matcher = Mockito.mock(CombiningMatcher.class);
4854

4955
_configurations = new HashMap<>();
@@ -63,87 +69,87 @@ public void evaluateWhenSplitNameDoesNotExistReturnControl() throws ChangeNumber
6369

6470
@Test
6571
public void evaluateWhenSplitIsKilledReturnDefaultTreatment() throws ChangeNumberExceptionWrapper {
66-
ParsedSplit split = ParsedSplit.createParsedSplitForTests(_splitName, 0, true, "defaultTreatment", _conditions, "tt", _changeNumber, 2);
72+
ParsedSplit split = ParsedSplit.createParsedSplitForTests(_splitName, 0, true, _defaultTreatmentValue, _conditions, _trafficTypeValue, _changeNumber, 2);
6773
Mockito.when(_splitFetcher.fetch(_splitName)).thenReturn(split);
6874

6975
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(_matchingKey, _bucketingKey, _splitName, null, _splitClient);
7076

71-
assertEquals("defaultTreatment", result.treatment);
77+
assertEquals(_defaultTreatmentValue, result.treatment);
7278
assertEquals("killed", result.label);
7379
assertEquals(_changeNumber, result.changeNumber);
7480
}
7581

7682
@Test
7783
public void evaluateWithoutConditionsReturnDefaultTreatment() throws ChangeNumberExceptionWrapper {
78-
ParsedSplit split = ParsedSplit.createParsedSplitForTests(_splitName, 0, false, "defaultTreatment", _conditions, "tt", _changeNumber, 2);
84+
ParsedSplit split = ParsedSplit.createParsedSplitForTests(_splitName, 0, false, _defaultTreatmentValue, _conditions, _trafficTypeValue, _changeNumber, 2);
7985
Mockito.when(_splitFetcher.fetch(_splitName)).thenReturn(split);
8086

8187
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(_matchingKey, _bucketingKey, _splitName, null, _splitClient);
8288

83-
assertEquals("defaultTreatment", result.treatment);
89+
assertEquals(_defaultTreatmentValue, result.treatment);
8490
assertEquals("default rule", result.label);
8591
assertEquals(_changeNumber, result.changeNumber);
8692
}
8793

8894
@Test
8995
public void evaluateWithRollOutConditionBucketIsBiggerTrafficAllocationReturnDefaultTreatment() throws ChangeNumberExceptionWrapper {
9096
Partition partition = new Partition();
91-
partition.treatment = "treatment_test";
97+
partition.treatment = _treatmentValue;
9298
partition.size = 100;
9399
_partitions.add(partition);
94-
ParsedCondition condition = new ParsedCondition(ConditionType.ROLLOUT, _matcher,_partitions, "test label");
100+
ParsedCondition condition = new ParsedCondition(ConditionType.ROLLOUT, _matcher,_partitions, _testLabelValue);
95101
_conditions.add(condition);
96102

97-
ParsedSplit split = new ParsedSplit(_splitName, 0, false, "default_treatment", _conditions, "tt", _changeNumber, 10, 12, 2, _configurations);
103+
ParsedSplit split = new ParsedSplit(_splitName, 0, false, _defaultTreatmentValue, _conditions, _trafficTypeValue, _changeNumber, 10, 12, 2, _configurations);
98104

99105
Mockito.when(_splitFetcher.fetch(_splitName)).thenReturn(split);
100106
Mockito.when(condition.matcher().match(_matchingKey, _bucketingKey, null, _splitClient)).thenReturn(true);
101107

102108
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(_matchingKey, _bucketingKey, _splitName, null, _splitClient);
103109

104-
assertEquals("default_treatment", result.treatment);
110+
assertEquals(_defaultTreatmentValue, result.treatment);
105111
assertEquals("not in split", result.label);
106112
assertEquals(_changeNumber, result.changeNumber);
107113
}
108114

109115
@Test
110116
public void evaluateWithRollOutConditionTrafficAllocationIsBiggerBucketReturnTreatment() throws ChangeNumberExceptionWrapper {
111117
Partition partition = new Partition();
112-
partition.treatment = "treatment_test";
118+
partition.treatment = _treatmentValue;
113119
partition.size = 100;
114120
_partitions.add(partition);
115-
ParsedCondition condition = new ParsedCondition(ConditionType.ROLLOUT, _matcher, _partitions, "test label");
121+
ParsedCondition condition = new ParsedCondition(ConditionType.ROLLOUT, _matcher, _partitions, _testLabelValue);
116122
_conditions.add(condition);
117123

118-
ParsedSplit split = new ParsedSplit(_splitName, 0, false, "default_treatment", _conditions, "tt", _changeNumber, 60, 18, 2, _configurations);
124+
ParsedSplit split = new ParsedSplit(_splitName, 0, false, _defaultTreatmentValue, _conditions, _trafficTypeValue, _changeNumber, 60, 18, 2, _configurations);
119125

120126
Mockito.when(_splitFetcher.fetch(_splitName)).thenReturn(split);
121127
Mockito.when(condition.matcher().match(_matchingKey, _bucketingKey, null, _splitClient)).thenReturn(true);
122128

123129
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(_matchingKey, _bucketingKey, _splitName, null, _splitClient);
124130

125-
assertEquals("treatment_test", result.treatment);
126-
assertEquals("test label", result.label);
131+
assertEquals(_treatmentValue, result.treatment);
132+
assertEquals(_testLabelValue, result.label);
127133
assertEquals(_changeNumber, result.changeNumber);
128134
}
129135

130136
@Test
131137
public void evaluateWithWhitelistConditionReturnTreatment() throws ChangeNumberExceptionWrapper {
132138
Partition partition = new Partition();
133-
partition.treatment = "treatment_test";
139+
partition.treatment = _treatmentValue;
134140
partition.size = 100;
135141
_partitions.add(partition);
136142
ParsedCondition condition = new ParsedCondition(ConditionType.WHITELIST, _matcher, _partitions, "test whitelist label");
137143
_conditions.add(condition);
138144

139-
ParsedSplit split = new ParsedSplit(_splitName, 0, false, "default_treatment", _conditions, "tt", _changeNumber, 60, 18, 2, _configurations);
145+
ParsedSplit split = new ParsedSplit(_splitName, 0, false, _defaultTreatmentValue, _conditions, _trafficTypeValue, _changeNumber, 60, 18, 2, _configurations);
140146

141147
Mockito.when(_splitFetcher.fetch(_splitName)).thenReturn(split);
142148
Mockito.when(condition.matcher().match(_matchingKey, _bucketingKey, null, _splitClient)).thenReturn(true);
143149

144150
TreatmentLabelAndChangeNumber result = _evaluator.evaluateFeature(_matchingKey, _bucketingKey, _splitName, null, _splitClient);
145151

146-
assertEquals("treatment_test", result.treatment);
152+
assertEquals(_treatmentValue, result.treatment);
147153
assertEquals("test whitelist label", result.label);
148154
assertEquals(_changeNumber, result.changeNumber);
149155
}

0 commit comments

Comments
 (0)