How to use then method of org.hamcrest.Condition class

Best junit code snippet using org.hamcrest.Condition.then

Source:SplitClientImplTest.java Github

copy

Full Screen

...78 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);79 SDKReadinessGates gates = mock(SDKReadinessGates.class);80 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);81 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);82 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);83 SplitClientImpl client = new SplitClientImpl(84 mock(SplitFactory.class),85 splitCacheConsumer,86 new ImpressionsManager.NoOpImpressionsManager(),87 NoopEventsStorageImp.create(),88 config,89 gates,90 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE91 );92 assertThat(client.getTreatment(null, "test1"), is(equalTo(Treatments.CONTROL)));93 verifyZeroInteractions(splitCacheConsumer);94 }95 @Test96 public void null_test_results_in_control() {97 String test = "test1";98 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));99 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);100 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);101 SDKReadinessGates gates = mock(SDKReadinessGates.class);102 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);103 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);104 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);105 SplitClientImpl client = new SplitClientImpl(106 mock(SplitFactory.class),107 splitCacheConsumer,108 new ImpressionsManager.NoOpImpressionsManager(),109 NoopEventsStorageImp.create(),110 config,111 gates,112 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE113 );114 assertThat(client.getTreatment("adil@relateiq.com", null), is(equalTo(Treatments.CONTROL)));115 verifyZeroInteractions(splitCacheConsumer);116 }117 @Test118 public void exceptions_result_in_control() {119 SDKReadinessGates gates = mock(SDKReadinessGates.class);120 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);121 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);122 when(splitCacheConsumer.get(anyString())).thenThrow(RuntimeException.class);123 SplitClientImpl client = new SplitClientImpl(124 mock(SplitFactory.class),125 splitCacheConsumer,126 new ImpressionsManager.NoOpImpressionsManager(),127 NoopEventsStorageImp.create(),128 config,129 gates,130 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE131 );132 assertThat(client.getTreatment("adil@relateiq.com", "test1"), is(equalTo(Treatments.CONTROL)));133 verify(splitCacheConsumer).get("test1");134 }135 @Test136 public void works() {137 String test = "test1";138 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));139 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);140 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);141 SDKReadinessGates gates = mock(SDKReadinessGates.class);142 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);143 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);144 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);145 when(gates.isSDKReady()).thenReturn(true);146 SplitClientImpl client = new SplitClientImpl(147 mock(SplitFactory.class),148 splitCacheConsumer,149 new ImpressionsManager.NoOpImpressionsManager(),150 NoopEventsStorageImp.create(),151 config,152 gates,153 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE154 );155 int numKeys = 5;156 for (int i = 0; i < numKeys; i++) {157 String randomKey = RandomStringUtils.random(10);158 assertThat(client.getTreatment(randomKey, test), is(equalTo("on")));159 }160 verify(splitCacheConsumer, times(numKeys)).get(test);161 verify(TELEMETRY_STORAGE, times(5)).recordLatency(Mockito.anyObject(), Mockito.anyLong());162 }163 /**164 * There is no config for this treatment165 */166 @Test167 public void works_null_config() {168 String test = "test1";169 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));170 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);171 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);172 SDKReadinessGates gates = mock(SDKReadinessGates.class);173 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);174 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);175 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);176 SplitClientImpl client = new SplitClientImpl(177 mock(SplitFactory.class),178 splitCacheConsumer,179 new ImpressionsManager.NoOpImpressionsManager(),180 NoopEventsStorageImp.create(),181 config,182 gates,183 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE184 );185 String randomKey = RandomStringUtils.random(10);186 SplitResult result = client.getTreatmentWithConfig(randomKey, test);187 assertThat(result.treatment(), is(equalTo(Treatments.ON)));188 assertThat(result.config(), is(nullValue()));189 verify(splitCacheConsumer).get(test);190 }191 @Test192 public void worksAndHasConfig() {193 String test = "test1";194 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));195 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);196 // Add config for only one treatment197 Map<String, String> configurations = new HashMap<>();198 configurations.put(Treatments.ON, "{\"size\" : 30}");199 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1, configurations);200 SDKReadinessGates gates = mock(SDKReadinessGates.class);201 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);202 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);203 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);204 SplitClientImpl client = new SplitClientImpl(205 mock(SplitFactory.class),206 splitCacheConsumer,207 new ImpressionsManager.NoOpImpressionsManager(),208 NoopEventsStorageImp.create(),209 config,210 gates,211 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE212 );213 int numKeys = 5;214 for (int i = 0; i < numKeys; i++) {215 Map<String, Object> attributes = new HashMap<>();216 String randomKey = RandomStringUtils.random(10);217 assertThat(client.getTreatment(randomKey, test), is(equalTo("on")));218 assertThat(client.getTreatmentWithConfig(randomKey, test, attributes).config(), is(equalTo(configurations.get("on"))));219 }220 // Times 2 because we are calling getTreatment twice. Once for getTreatment and one for getTreatmentWithConfig221 verify(splitCacheConsumer, times(numKeys * 2)).get(test);222 }223 @Test224 public void last_condition_is_always_default() {225 String test = "test1";226 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("adil@codigo.com"))), Lists.newArrayList(partition("on", 100)));227 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);228 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, "user", 1, 1);229 SDKReadinessGates gates = mock(SDKReadinessGates.class);230 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);231 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);232 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);233 SplitClientImpl client = new SplitClientImpl(234 mock(SplitFactory.class),235 splitCacheConsumer,236 new ImpressionsManager.NoOpImpressionsManager(),237 NoopEventsStorageImp.create(),238 config,239 gates,240 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE241 );242 assertThat(client.getTreatment("pato@codigo.com", test), is(equalTo(Treatments.OFF)));243 verify(splitCacheConsumer).get(test);244 }245 /**246 * Tests that we retrieve configs from the default treatment247 */248 @Test249 public void last_condition_is_always_default_but_with_treatment() {250 String test = "test1";251 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("adil@codigo.com"))), Lists.newArrayList(partition("on", 100)));252 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);253 // Add config for only one treatment(default)254 Map<String, String> configurations = new HashMap<>();255 configurations.put(Treatments.OFF, "{\"size\" : 30}");256 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, "user", 1, 1, configurations);257 SDKReadinessGates gates = mock(SDKReadinessGates.class);258 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);259 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);260 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);261 SplitClientImpl client = new SplitClientImpl(262 mock(SplitFactory.class),263 splitCacheConsumer,264 new ImpressionsManager.NoOpImpressionsManager(),265 NoopEventsStorageImp.create(),266 config,267 gates,268 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE269 );270 SplitResult result = client.getTreatmentWithConfig("pato@codigo.com", test);271 assertThat(result.treatment(), is(equalTo(Treatments.OFF)));272 assertThat(result.config(), is(equalTo("{\"size\" : 30}")));273 verify(splitCacheConsumer).get(test);274 }275 @Test276 public void multiple_conditions_work() {277 String test = "test1";278 ParsedCondition adil_is_always_on = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("adil@codigo.com"))), Lists.newArrayList(partition("on", 100)));279 ParsedCondition pato_is_never_shown = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("pato@codigo.com"))), Lists.newArrayList(partition("off", 100)));280 ParsedCondition trevor_is_always_shown = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("trevor@codigo.com"))), Lists.newArrayList(partition("on", 100)));281 List<ParsedCondition> conditions = Lists.newArrayList(adil_is_always_on, pato_is_never_shown, trevor_is_always_shown);282 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);283 SDKReadinessGates gates = mock(SDKReadinessGates.class);284 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);285 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);286 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);287 when(gates.isSDKReady()).thenReturn(false);288 SplitClientImpl client = new SplitClientImpl(289 mock(SplitFactory.class),290 splitCacheConsumer,291 new ImpressionsManager.NoOpImpressionsManager(),292 NoopEventsStorageImp.create(),293 config,294 gates,295 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE296 );297 assertThat(client.getTreatment("adil@codigo.com", test), is(equalTo("on")));298 assertThat(client.getTreatment("pato@codigo.com", test), is(equalTo("off")));299 assertThat(client.getTreatment("trevor@codigo.com", test), is(equalTo("on")));300 verify(splitCacheConsumer, times(3)).get(test);301 verify(TELEMETRY_STORAGE, times(3)).recordNonReadyUsage();302 }303 @Test304 public void killed_test_always_goes_to_default() {305 String test = "test1";306 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("adil@codigo.com"))), Lists.newArrayList(partition("on", 100)));307 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);308 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, true, Treatments.OFF, conditions, "user", 1, 1);309 SDKReadinessGates gates = mock(SDKReadinessGates.class);310 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);311 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);312 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);313 SplitClientImpl client = new SplitClientImpl(314 mock(SplitFactory.class),315 splitCacheConsumer,316 new ImpressionsManager.NoOpImpressionsManager(),317 NoopEventsStorageImp.create(),318 config,319 gates,320 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE321 );322 assertThat(client.getTreatment("adil@codigo.com", test), is(equalTo(Treatments.OFF)));323 verify(splitCacheConsumer).get(test);324 }325 /**326 * when killed, the evaluator follows a slightly different path. So testing that when there is a config.327 */328 @Test329 public void killed_test_always_goes_to_default_has_config() {330 String test = "test1";331 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("adil@codigo.com"))), Lists.newArrayList(partition("on", 100)));332 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);333 // Add config for only one treatment(default)334 Map<String, String> configurations = new HashMap<>();335 configurations.put(Treatments.OFF, "{\"size\" : 30}");336 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, true, Treatments.OFF, conditions, "user", 1, 1, configurations);337 SDKReadinessGates gates = mock(SDKReadinessGates.class);338 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);339 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);340 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);341 SplitClientImpl client = new SplitClientImpl(342 mock(SplitFactory.class),343 splitCacheConsumer,344 new ImpressionsManager.NoOpImpressionsManager(),345 NoopEventsStorageImp.create(),346 config,347 gates,348 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE349 );350 SplitResult result = client.getTreatmentWithConfig("adil@codigo.com", test);351 assertThat(result.treatment(), is(equalTo(Treatments.OFF)));352 assertThat(result.config(), is(equalTo("{\"size\" : 30}")));353 verify(splitCacheConsumer).get(test);354 }355 @Test356 public void dependency_matcher_on() {357 String parent = "parent";358 String dependent = "dependent";359 ParsedCondition parent_is_on = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition(Treatments.ON, 100)));360 List<ParsedCondition> parent_conditions = Lists.newArrayList(parent_is_on);361 ParsedSplit parentSplit = ParsedSplit.createParsedSplitForTests(parent, 123, false, Treatments.OFF, parent_conditions, null, 1, 1);362 ParsedCondition dependent_needs_parent = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new DependencyMatcher(parent, Lists.newArrayList(Treatments.ON))), Lists.newArrayList(partition(Treatments.ON, 100)));363 List<ParsedCondition> dependent_conditions = Lists.newArrayList(dependent_needs_parent);364 ParsedSplit dependentSplit = ParsedSplit.createParsedSplitForTests(dependent, 123, false, Treatments.OFF, dependent_conditions, null, 1, 1);365 SDKReadinessGates gates = mock(SDKReadinessGates.class);366 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);367 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);368 when(splitCacheConsumer.get(parent)).thenReturn(parentSplit);369 when(splitCacheConsumer.get(dependent)).thenReturn(dependentSplit);370 SplitClientImpl client = new SplitClientImpl(371 mock(SplitFactory.class),372 splitCacheConsumer,373 new ImpressionsManager.NoOpImpressionsManager(),374 NoopEventsStorageImp.create(),375 config,376 gates,377 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE378 );379 assertThat(client.getTreatment("key", parent), is(equalTo(Treatments.ON)));380 assertThat(client.getTreatment("key", dependent), is(equalTo(Treatments.ON)));381 }382 @Test383 public void dependency_matcher_off() {384 String parent = "parent";385 String dependent = "dependent";386 ParsedCondition parent_is_on = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition(Treatments.ON, 100)));387 List<ParsedCondition> parent_conditions = Lists.newArrayList(parent_is_on);388 ParsedSplit parentSplit = ParsedSplit.createParsedSplitForTests(parent, 123, false, Treatments.OFF, parent_conditions, null, 1, 1);389 ParsedCondition dependent_needs_parent = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new DependencyMatcher(parent, Lists.newArrayList(Treatments.OFF))), Lists.newArrayList(partition(Treatments.ON, 100)));390 List<ParsedCondition> dependent_conditions = Lists.newArrayList(dependent_needs_parent);391 ParsedSplit dependentSplit = ParsedSplit.createParsedSplitForTests(dependent, 123, false, Treatments.OFF, dependent_conditions, null, 1, 1);392 SDKReadinessGates gates = mock(SDKReadinessGates.class);393 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);394 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);395 when(splitCacheConsumer.get(parent)).thenReturn(parentSplit);396 when(splitCacheConsumer.get(dependent)).thenReturn(dependentSplit);397 SplitClientImpl client = new SplitClientImpl(398 mock(SplitFactory.class),399 splitCacheConsumer,400 new ImpressionsManager.NoOpImpressionsManager(),401 NoopEventsStorageImp.create(),402 config,403 gates,404 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE405 );406 assertThat(client.getTreatment("key", parent), is(equalTo(Treatments.ON)));407 assertThat(client.getTreatment("key", dependent), is(equalTo(Treatments.OFF)));408 }409 @Test410 public void dependency_matcher_control() {411 String dependent = "dependent";412 ParsedCondition dependent_needs_parent = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new DependencyMatcher("not-exists", Lists.newArrayList(Treatments.OFF))), Lists.newArrayList(partition(Treatments.OFF, 100)));413 List<ParsedCondition> dependent_conditions = Lists.newArrayList(dependent_needs_parent);414 ParsedSplit dependentSplit = ParsedSplit.createParsedSplitForTests(dependent, 123, false, Treatments.ON, dependent_conditions, null, 1, 1);415 SDKReadinessGates gates = mock(SDKReadinessGates.class);416 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);417 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);418 when(splitCacheConsumer.get(dependent)).thenReturn(dependentSplit);419 SplitClientImpl client = new SplitClientImpl(420 mock(SplitFactory.class),421 splitCacheConsumer,422 new ImpressionsManager.NoOpImpressionsManager(),423 NoopEventsStorageImp.create(),424 config,425 gates,426 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE427 );428 assertThat(client.getTreatment("key", dependent), is(equalTo(Treatments.ON)));429 }430 @Test431 public void attributes_work() {432 String test = "test1";433 ParsedCondition adil_is_always_on = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("adil@codigo.com"))), Lists.newArrayList(partition(Treatments.ON, 100)));434 ParsedCondition users_with_age_greater_than_10_are_on = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of("age", new GreaterThanOrEqualToMatcher(10, DataType.NUMBER)), Lists.newArrayList(partition("on", 100)));435 List<ParsedCondition> conditions = Lists.newArrayList(adil_is_always_on, users_with_age_greater_than_10_are_on);436 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);437 SDKReadinessGates gates = mock(SDKReadinessGates.class);438 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);439 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);440 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);441 SplitClientImpl client = new SplitClientImpl(442 mock(SplitFactory.class),443 splitCacheConsumer,444 new ImpressionsManager.NoOpImpressionsManager(),445 NoopEventsStorageImp.create(),446 config,447 gates,448 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE449 );450 assertThat(client.getTreatment("adil@codigo.com", test), is(equalTo("on")));451 assertThat(client.getTreatment("adil@codigo.com", test, null), is(equalTo("on")));452 assertThat(client.getTreatment("adil@codigo.com", test, ImmutableMap.<String, Object>of()), is(equalTo("on")));453 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("age", 10)), is(equalTo("on")));454 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("age", 9)), is(equalTo("off")));455 verify(splitCacheConsumer, times(5)).get(test);456 }457 @Test458 public void attributes_work_2() {459 String test = "test1";460 ParsedCondition age_equal_to_0_should_be_on = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of("age", new EqualToMatcher(0, DataType.NUMBER)), Lists.newArrayList(partition("on", 100)));461 List<ParsedCondition> conditions = Lists.newArrayList(age_equal_to_0_should_be_on);462 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, "user", 1, 1);463 SDKReadinessGates gates = mock(SDKReadinessGates.class);464 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);465 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);466 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);467 SplitClientImpl client = new SplitClientImpl(468 mock(SplitFactory.class),469 splitCacheConsumer,470 new ImpressionsManager.NoOpImpressionsManager(),471 NoopEventsStorageImp.create(),472 config,473 gates,474 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE475 );476 assertThat(client.getTreatment("adil@codigo.com", test), is(equalTo("off")));477 assertThat(client.getTreatment("adil@codigo.com", test, null), is(equalTo("off")));478 assertThat(client.getTreatment("adil@codigo.com", test, ImmutableMap.<String, Object>of()), is(equalTo("off")));479 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("age", 10)), is(equalTo("off")));480 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("age", 0)), is(equalTo("on")));481 verify(splitCacheConsumer, times(5)).get(test);482 }483 @Test484 public void attributes_greater_than_negative_number() {485 String test = "test1";486 ParsedCondition age_equal_to_0_should_be_on = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of("age", new EqualToMatcher(-20, DataType.NUMBER)), Lists.newArrayList(partition("on", 100)));487 List<ParsedCondition> conditions = Lists.newArrayList(age_equal_to_0_should_be_on);488 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);489 SDKReadinessGates gates = mock(SDKReadinessGates.class);490 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);491 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);492 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);493 SplitClientImpl client = new SplitClientImpl(494 mock(SplitFactory.class),495 splitCacheConsumer,496 new ImpressionsManager.NoOpImpressionsManager(),497 NoopEventsStorageImp.create(),498 config,499 gates,500 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE501 );502 assertThat(client.getTreatment("adil@codigo.com", test), is(equalTo("off")));503 assertThat(client.getTreatment("adil@codigo.com", test, null), is(equalTo("off")));504 assertThat(client.getTreatment("adil@codigo.com", test, ImmutableMap.<String, Object>of()), is(equalTo("off")));505 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("age", 10)), is(equalTo("off")));506 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("age", -20)), is(equalTo("on")));507 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("age", 20)), is(equalTo("off")));508 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("age", -21)), is(equalTo("off")));509 verify(splitCacheConsumer, times(7)).get(test);510 }511 @Test512 public void attributes_for_sets() {513 String test = "test1";514 ParsedCondition any_of_set = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of("products", new ContainsAnyOfSetMatcher(Lists.<String>newArrayList("sms", "video"))), Lists.newArrayList(partition("on", 100)));515 List<ParsedCondition> conditions = Lists.newArrayList(any_of_set);516 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);517 SDKReadinessGates gates = mock(SDKReadinessGates.class);518 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);519 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);520 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);521 SplitClientImpl client = new SplitClientImpl(522 mock(SplitFactory.class),523 splitCacheConsumer,524 new ImpressionsManager.NoOpImpressionsManager(),525 NoopEventsStorageImp.create(),526 config,527 gates,528 new EvaluatorImp(splitCacheConsumer ,segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE529 );530 assertThat(client.getTreatment("adil@codigo.com", test), is(equalTo("off")));531 assertThat(client.getTreatment("adil@codigo.com", test, null), is(equalTo("off")));532 assertThat(client.getTreatment("adil@codigo.com", test, ImmutableMap.<String, Object>of()), is(equalTo("off")));533 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("products", Lists.newArrayList())), is(equalTo("off")));534 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("products", Lists.newArrayList(""))), is(equalTo("off")));535 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("products", Lists.newArrayList("talk"))), is(equalTo("off")));536 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("products", Lists.newArrayList("sms"))), is(equalTo("on")));537 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("products", Lists.newArrayList("sms", "video"))), is(equalTo("on")));538 assertThat(client.getTreatment("pato@codigo.com", test, ImmutableMap.<String, Object>of("products", Lists.newArrayList("video"))), is(equalTo("on")));539 verify(splitCacheConsumer, times(9)).get(test);540 }541 @Test542 public void labels_are_populated() {543 String test = "test1";544 ParsedCondition age_equal_to_0_should_be_on = new ParsedCondition(ConditionType.ROLLOUT,545 CombiningMatcher.of("age", new EqualToMatcher(-20, DataType.NUMBER)),546 Lists.newArrayList(partition("on", 100)),547 "foolabel"548 );549 List<ParsedCondition> conditions = Lists.newArrayList(age_equal_to_0_should_be_on);550 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);551 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);552 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);553 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);554 SDKReadinessGates gates = mock(SDKReadinessGates.class);555 ImpressionsManager impressionsManager = mock(ImpressionsManager.class);556 SplitClientImpl client = new SplitClientImpl(557 mock(SplitFactory.class),558 splitCacheConsumer,559 impressionsManager,560 NoopEventsStorageImp.create(),561 config,562 gates,563 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE564 );565 Map<String, Object> attributes = ImmutableMap.<String, Object>of("age", -20, "acv", "1000000");566 assertThat(client.getTreatment("pato@codigo.com", test, attributes), is(equalTo("on")));567 ArgumentCaptor<List> impressionCaptor = ArgumentCaptor.forClass(List.class);568 verify(impressionsManager).track(impressionCaptor.capture());569 List<Impression> impressions = impressionCaptor.getValue();570 assertNotNull(impressions);571 assertEquals(1, impressions.size());572 Impression impression = impressions.get(0);573 assertThat(impression.appliedRule(), is(equalTo("foolabel")));574 assertThat(impression.attributes(), is(attributes));575 }576 @Test577 public void not_in_split_if_no_allocation() {578 traffic_allocation("pato@split.io", 0, 123, "off", "not in split");579 }580 /**581 * This test depends on the underlying hashing algorithm. I have582 * figured out that pato@split.io will be in bucket 9 for seed 123.583 * That is why the test has been set up this way.584 *585 * If the underlying hashing algorithm changes, say to murmur, then we will586 * have to update this test.587 *588 * @author adil589 */590 @Test591 public void not_in_split_if_10_percent_allocation() {592 String key = "pato@split.io";593 int i = 0;594 for (; i <= 9; i++) {595 traffic_allocation(key, i, 123, "off", "not in split");596 }597 for (; i <= 100; i++) {598 traffic_allocation(key, i, 123, "on", "in segment all");599 }600 }601 @Test602 public void traffic_allocation_one_percent() {603 //This key, with this seed it should fall in the 1%604 String fallsInOnePercent = "pato193";605 traffic_allocation(fallsInOnePercent, 1, 123, "on", "in segment all");606 //All these others should not be in split607 for (int offset = 0; offset <= 100; offset++) {608 traffic_allocation("pato" + String.valueOf(offset), 1, 123, "off", "not in split");609 }610 }611 @Test612 public void in_split_if_100_percent_allocation() {613 traffic_allocation("pato@split.io", 100, 123, "on", "in segment all");614 }615 @Test616 public void whitelist_overrides_traffic_allocation() {617 traffic_allocation("adil@split.io", 0, 123, "on", "whitelisted user");618 }619 private void traffic_allocation(String key, int trafficAllocation, int trafficAllocationSeed, String expected_treatment_on_or_off, String label) {620 String test = "test1";621 ParsedCondition whitelistCondition = new ParsedCondition(ConditionType.WHITELIST, CombiningMatcher.of(new WhitelistMatcher(Lists.newArrayList("adil@split.io"))), Lists.newArrayList(partition("on", 100), partition("off", 0)), "whitelisted user");622 ParsedCondition rollOutToEveryone = new ParsedCondition(ConditionType.ROLLOUT, CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100), partition("off", 0)), "in segment all");623 List<ParsedCondition> conditions = Lists.newArrayList(whitelistCondition, rollOutToEveryone);624 ParsedSplit parsedSplit = new ParsedSplit(test, 123, false, Treatments.OFF, conditions, null, 1, trafficAllocation, trafficAllocationSeed, 1, null);625 SDKReadinessGates gates = mock(SDKReadinessGates.class);626 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);627 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);628 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);629 ImpressionsManager impressionsManager = mock(ImpressionsManager.class);630 SplitClientImpl client = new SplitClientImpl(631 mock(SplitFactory.class),632 splitCacheConsumer,633 impressionsManager,634 NoopEventsStorageImp.create(),635 config,636 gates,637 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE638 );639 assertThat(client.getTreatment(key, test), is(equalTo(expected_treatment_on_or_off)));640 ArgumentCaptor<List> impressionCaptor = ArgumentCaptor.forClass(List.class);641 verify(impressionsManager).track(impressionCaptor.capture());642 assertNotNull(impressionCaptor.getValue());643 assertEquals(1, impressionCaptor.getValue().size());644 Impression impression = (Impression) impressionCaptor.getValue().get(0);645 assertThat(impression.appliedRule(), is(equalTo(label)));646 }647 /**648 * Tests that when the key is not in the traffic allocation, it gets the default config when it exists.649 */650 @Test651 public void notInTrafficAllocationDefaultConfig() {652 String test = "test1";653 int trafficAllocation = 0;654 int trafficAllocationSeed = 123;655 // Add config for only one treatment656 Map<String, String> configurations = new HashMap<>();657 configurations.put(Treatments.ON, "{\"size\" : 30}");658 configurations.put(Treatments.OFF, "{\"size\" : 30}"); // OFF is default treatment659 ParsedCondition rollOutToEveryone = new ParsedCondition(ConditionType.ROLLOUT, CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100), partition("off", 0)), "in segment all");660 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);661 ParsedSplit parsedSplit = new ParsedSplit(test, 123, false, Treatments.OFF, conditions, null, 1, trafficAllocation, trafficAllocationSeed, 1, configurations);662 SDKReadinessGates gates = mock(SDKReadinessGates.class);663 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);664 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);665 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);666 ImpressionsManager impressionsManager = mock(ImpressionsManager.class);667 SplitClientImpl client = new SplitClientImpl(668 mock(SplitFactory.class),669 splitCacheConsumer,670 impressionsManager,671 NoopEventsStorageImp.create(),672 config,673 gates,674 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE675 );676 assertThat(client.getTreatment("pato@split.io", test), is(equalTo(Treatments.OFF)));677 SplitResult result = client.getTreatmentWithConfig("pato@split.io", test);678 assertThat(result.treatment(), is(equalTo(Treatments.OFF)));679 assertThat(result.config(), is(equalTo("{\"size\" : 30}")));680 ArgumentCaptor<List> impressionCaptor = ArgumentCaptor.forClass(List.class);681 verify(impressionsManager, times(2)).track(impressionCaptor.capture());682 assertNotNull(impressionCaptor.getValue());683 assertEquals(1, impressionCaptor.getValue().size());684 Impression impression = (Impression) impressionCaptor.getValue().get(0);685 assertThat(impression.appliedRule(), is(equalTo("not in split")));686 }687 @Test688 public void matching_bucketing_keys_work() {689 String test = "test1";690 Set<String> whitelist = new HashSet<>();691 whitelist.add("aijaz");692 ParsedCondition aijaz_should_match = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new WhitelistMatcher(whitelist)), Lists.newArrayList(partition("on", 100)));693 List<ParsedCondition> conditions = Lists.newArrayList(aijaz_should_match);694 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, "user", 1, 1);695 SDKReadinessGates gates = mock(SDKReadinessGates.class);696 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);697 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);698 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);699 SplitClientImpl client = new SplitClientImpl(700 mock(SplitFactory.class),701 splitCacheConsumer,702 new ImpressionsManager.NoOpImpressionsManager(),703 NoopEventsStorageImp.create(),704 config,705 gates,706 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE707 );708 Key bad_key = new Key("adil", "aijaz");709 Key good_key = new Key("aijaz", "adil");710 assertThat(client.getTreatment(bad_key, test, Collections.<String, Object>emptyMap()), is(equalTo("off")));711 assertThat(client.getTreatment(good_key, test, Collections.<String, Object>emptyMap()), is(equalTo("on")));712 verify(splitCacheConsumer, times(2)).get(test);713 }714 @Test715 public void impression_metadata_is_propagated() {716 String test = "test1";717 ParsedCondition age_equal_to_0_should_be_on = new ParsedCondition(ConditionType.ROLLOUT,718 CombiningMatcher.of("age", new EqualToMatcher(-20, DataType.NUMBER)),719 Lists.newArrayList(partition("on", 100)),720 "foolabel"721 );722 List<ParsedCondition> conditions = Lists.newArrayList(age_equal_to_0_should_be_on);723 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);724 SDKReadinessGates gates = mock(SDKReadinessGates.class);725 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);726 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);727 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);728 ImpressionsManager impressionsManager = mock(ImpressionsManager.class);729 SplitClientImpl client = new SplitClientImpl(730 mock(SplitFactory.class),731 splitCacheConsumer,732 impressionsManager,733 NoopEventsStorageImp.create(),734 config,735 gates,736 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE737 );738 Map<String, Object> attributes = ImmutableMap.<String, Object>of("age", -20, "acv", "1000000");739 assertThat(client.getTreatment("pato@codigo.com", test, attributes), is(equalTo("on")));740 ArgumentCaptor<List> impressionCaptor = ArgumentCaptor.forClass(List.class);741 verify(impressionsManager).track(impressionCaptor.capture());742 assertNotNull(impressionCaptor.getValue());743 assertEquals(1, impressionCaptor.getValue().size());744 Impression impression = (Impression) impressionCaptor.getValue().get(0);745 assertThat(impression.appliedRule(), is(equalTo("foolabel")));746 assertThat(impression.attributes(), is(equalTo(attributes)));747 }748 private Partition partition(String treatment, int size) {749 Partition p = new Partition();750 p.treatment = treatment;751 p.size = size;752 return p;753 }754 @Test755 public void block_until_ready_does_not_time_when_sdk_is_ready() throws TimeoutException, InterruptedException {756 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);757 SDKReadinessGates ready = mock(SDKReadinessGates.class);758 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);759 when(ready.waitUntilInternalReady(100)).thenReturn(true);760 SplitClientImpl client = new SplitClientImpl(761 mock(SplitFactory.class),762 splitCacheConsumer,763 mock(ImpressionsManager.class),764 NoopEventsStorageImp.create(),765 config,766 ready,767 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE768 );769 client.blockUntilReady();770 }771 @Test(expected = TimeoutException.class)772 public void block_until_ready_times_when_sdk_is_not_ready() throws TimeoutException, InterruptedException {773 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);774 SDKReadinessGates ready = mock(SDKReadinessGates.class);775 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);776 when(ready.waitUntilInternalReady(100)).thenReturn(false);777 SplitClientImpl client = new SplitClientImpl(778 mock(SplitFactory.class),779 splitCacheConsumer,780 mock(ImpressionsManager.class),781 NoopEventsStorageImp.create(),782 config,783 ready,784 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE785 );786 client.blockUntilReady();787 }788 @Test789 public void track_with_valid_parameters() {790 SDKReadinessGates gates = mock(SDKReadinessGates.class);791 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);792 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);793 when(gates.isSDKReady()).thenReturn(false);794 SplitClientImpl client = new SplitClientImpl(795 mock(SplitFactory.class),796 splitCacheConsumer,797 new ImpressionsManager.NoOpImpressionsManager(),798 NoopEventsStorageImp.create(),799 config,800 gates,801 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE802 );803 Assert.assertThat(client.track("validKey", "valid_traffic_type", "valid_event"),804 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(true)));805 String validEventSize = new String(new char[80]).replace('\0', 'a');806 String validKeySize = new String(new char[250]).replace('\0', 'a');807 Assert.assertThat(client.track(validKeySize, "valid_traffic_type", validEventSize, 10),808 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(true)));809 verify(TELEMETRY_STORAGE, times(2)).recordLatency(Mockito.anyObject(), Mockito.anyLong());810 }811 @Test812 public void track_with_invalid_event_type_ids() {813 SDKReadinessGates gates = mock(SDKReadinessGates.class);814 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);815 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);816 817 SplitClientImpl client = new SplitClientImpl(818 mock(SplitFactory.class),819 splitCacheConsumer,820 new ImpressionsManager.NoOpImpressionsManager(),821 NoopEventsStorageImp.create(),822 config,823 gates,824 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE825 );826 Assert.assertThat(client.track("validKey", "valid_traffic_type", ""),827 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));828 Assert.assertThat(client.track("validKey", "valid_traffic_type", null),829 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));830 Assert.assertThat(client.track("validKey", "valid_traffic_type", "invalid#char"),831 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));832 String invalidEventSize = new String(new char[81]).replace('\0', 'a');833 Assert.assertThat(client.track("validKey", "valid_traffic_type", invalidEventSize),834 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));835 }836 @Test837 public void track_with_invalid_traffic_type_names() {838 SDKReadinessGates gates = mock(SDKReadinessGates.class);839 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);840 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);841 842 SplitClientImpl client = new SplitClientImpl(843 mock(SplitFactory.class),844 splitCacheConsumer,845 new ImpressionsManager.NoOpImpressionsManager(),846 NoopEventsStorageImp.create(),847 config,848 gates,849 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE850 );851 Assert.assertThat(client.track("validKey", "", "valid"),852 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));853 Assert.assertThat(client.track("validKey", null, "valid"),854 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));855 }856 @Test857 public void track_with_invalid_keys() {858 SDKReadinessGates gates = mock(SDKReadinessGates.class);859 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);860 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);861 862 SplitClientImpl client = new SplitClientImpl(863 mock(SplitFactory.class),864 splitCacheConsumer,865 new ImpressionsManager.NoOpImpressionsManager(),866 NoopEventsStorageImp.create(),867 config,868 gates,869 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE870 );871 Assert.assertThat(client.track("", "valid_traffic_type", "valid"),872 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));873 Assert.assertThat(client.track(null, "valid_traffic_type", "valid"),874 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));875 String invalidKeySize = new String(new char[251]).replace('\0', 'a');876 Assert.assertThat(client.track(invalidKeySize, "valid_traffic_type", "valid"),877 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));878 }879 @Test880 public void getTreatment_with_invalid_keys() {881 String test = "split";882 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));883 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);884 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);885 SDKReadinessGates gates = mock(SDKReadinessGates.class);886 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);887 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);888 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);889 SplitClientImpl client = new SplitClientImpl(890 mock(SplitFactory.class),891 splitCacheConsumer,892 new ImpressionsManager.NoOpImpressionsManager(),893 NoopEventsStorageImp.create(),894 config,895 gates,896 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE897 );898 Assert.assertThat(client.getTreatment("valid", "split"),899 org.hamcrest.Matchers.is(org.hamcrest.Matchers.not(Treatments.CONTROL)));900 Assert.assertThat(client.getTreatment("", "split"),901 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(Treatments.CONTROL)));902 Assert.assertThat(client.getTreatment(null, "split"),903 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(Treatments.CONTROL)));904 String invalidKeySize = new String(new char[251]).replace('\0', 'a');905 Assert.assertThat(client.getTreatment(invalidKeySize, "split"),906 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(Treatments.CONTROL)));907 Assert.assertThat(client.getTreatment("valid", ""),908 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(Treatments.CONTROL)));909 Assert.assertThat(client.getTreatment("valid", null),910 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(Treatments.CONTROL)));911 String matchingKey = new String(new char[250]).replace('\0', 'a');912 String bucketingKey = new String(new char[250]).replace('\0', 'a');913 Key key = new Key(matchingKey, bucketingKey);914 Assert.assertThat(client.getTreatment(key, "split", null),915 org.hamcrest.Matchers.is(org.hamcrest.Matchers.not(Treatments.CONTROL)));916 key = new Key("valid", "");917 Assert.assertThat(client.getTreatment(key, "split", null),918 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(Treatments.CONTROL)));919 key = new Key("", "valid");920 Assert.assertThat(client.getTreatment(key, "split", null),921 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(Treatments.CONTROL)));922 matchingKey = new String(new char[251]).replace('\0', 'a');923 bucketingKey = new String(new char[250]).replace('\0', 'a');924 key = new Key(matchingKey, bucketingKey);925 Assert.assertThat(client.getTreatment(key, "split", null),926 org.hamcrest.Matchers.is(org.hamcrest.Matchers.is(Treatments.CONTROL)));927 matchingKey = new String(new char[250]).replace('\0', 'a');928 bucketingKey = new String(new char[251]).replace('\0', 'a');929 key = new Key(matchingKey, bucketingKey);930 Assert.assertThat(client.getTreatment(key, "split", null),931 org.hamcrest.Matchers.is(org.hamcrest.Matchers.is(Treatments.CONTROL)));932 }933 @Test934 public void track_with_properties() {935 SDKReadinessGates gates = mock(SDKReadinessGates.class);936 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);937 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);938 EventsStorageProducer eventClientMock = Mockito.mock(EventsStorageProducer.class);939 Mockito.when(eventClientMock.track((Event) Mockito.any(), Mockito.anyInt())).thenReturn(true);940 SplitClientImpl client = new SplitClientImpl(941 mock(SplitFactory.class),942 splitCacheConsumer,943 new ImpressionsManager.NoOpImpressionsManager(),944 eventClientMock,945 config,946 gates,947 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE948 );949 HashMap<String, Object> properties = new HashMap<>();950 ArgumentCaptor<Event> eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);951 properties.put("ok_property", 123);952 properties.put("some_property", new Object());953 Assert.assertThat(client.track("key1", "user", "purchase", properties),954 org.hamcrest.Matchers.is(true));955 verify(eventClientMock).track(eventArgumentCaptor.capture(), Mockito.anyInt());956 Event captured = eventArgumentCaptor.getValue();957 Assert.assertThat(captured.properties.size(), org.hamcrest.Matchers.is(2));958 Assert.assertThat((Integer) captured.properties.get("ok_property"), org.hamcrest.Matchers.is(123));959 Assert.assertThat(captured.properties.get("some_property"), org.hamcrest.Matchers.nullValue());960 properties.clear();961 Mockito.reset(eventClientMock);962 Mockito.when(eventClientMock.track((Event) Mockito.any(), Mockito.anyInt())).thenReturn(true);963 properties.put("ok_property", 123);964 properties.put("some_property", Arrays.asList(1, 2, 3));965 Assert.assertThat(client.track("key1", "user", "purchase", properties),966 org.hamcrest.Matchers.is(true));967 eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);968 verify(eventClientMock).track(eventArgumentCaptor.capture(), Mockito.anyInt());969 captured = eventArgumentCaptor.getValue();970 Assert.assertThat(captured.properties.size(), org.hamcrest.Matchers.is(2));971 Assert.assertThat((Integer) captured.properties.get("ok_property"), org.hamcrest.Matchers.is(123));972 Assert.assertThat(captured.properties.get("some_property"), org.hamcrest.Matchers.nullValue());973 properties.clear();974 Mockito.reset(eventClientMock);975 Mockito.when(eventClientMock.track((Event) Mockito.any(), Mockito.anyInt())).thenReturn(true);976 properties.put("ok_property", 123);977 properties.put("some_property", new HashMap<String, Number>());978 Assert.assertThat(client.track("key1", "user", "purchase", properties),979 org.hamcrest.Matchers.is(true));980 eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);981 verify(eventClientMock).track(eventArgumentCaptor.capture(), Mockito.anyInt());982 captured = eventArgumentCaptor.getValue();983 Assert.assertThat(captured.properties.size(), org.hamcrest.Matchers.is(2));984 Assert.assertThat((Integer) captured.properties.get("ok_property"), org.hamcrest.Matchers.is(123));985 Assert.assertThat(captured.properties.get("some_property"), org.hamcrest.Matchers.nullValue());986 properties.clear();987 Mockito.reset(eventClientMock);988 Mockito.when(eventClientMock.track((Event) Mockito.any(), Mockito.anyInt())).thenReturn(true);989 properties.put("ok_property", 123);990 Assert.assertThat(client.track("key1", "user", "purchase", 123, properties),991 org.hamcrest.Matchers.is(true));992 eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);993 verify(eventClientMock).track(eventArgumentCaptor.capture(), Mockito.anyInt());994 captured = eventArgumentCaptor.getValue();995 Assert.assertThat(captured.value, org.hamcrest.Matchers.is(123.0));996 Assert.assertThat(captured.trafficTypeName,org.hamcrest.Matchers.is("user"));997 Assert.assertThat(captured.eventTypeId,org.hamcrest.Matchers.is("purchase"));998 Assert.assertThat(captured.key,org.hamcrest.Matchers.is("key1"));999 Assert.assertThat(captured.properties.size(), org.hamcrest.Matchers.is(1));1000 Assert.assertThat((Integer) captured.properties.get("ok_property"), org.hamcrest.Matchers.is(123));1001 properties.clear();1002 Mockito.reset(eventClientMock);1003 Mockito.when(eventClientMock.track((Event) Mockito.any(), Mockito.anyInt())).thenReturn(true);1004 properties.put("prop1", 1);1005 properties.put("prop2", 2L);1006 properties.put("prop3", 7.56);1007 properties.put("prop4", "something");1008 properties.put("prop5", true);1009 properties.put("prop6", null);1010 Assert.assertThat(client.track("key1", "user", "purchase", properties),1011 org.hamcrest.Matchers.is(true));1012 eventArgumentCaptor = ArgumentCaptor.forClass(Event.class);1013 verify(eventClientMock).track(eventArgumentCaptor.capture(), Mockito.anyInt());1014 captured = eventArgumentCaptor.getValue();1015 Assert.assertThat(captured.properties.size(), org.hamcrest.Matchers.is(6));1016 Assert.assertThat((Integer) captured.properties.get("prop1"), org.hamcrest.Matchers.is(1));1017 Assert.assertThat((Long) captured.properties.get("prop2"), org.hamcrest.Matchers.is(2L));1018 Assert.assertThat((Double) captured.properties.get("prop3"), org.hamcrest.Matchers.is(7.56));1019 Assert.assertThat((String) captured.properties.get("prop4"), org.hamcrest.Matchers.is("something"));1020 Assert.assertThat((Boolean) captured.properties.get("prop5"), org.hamcrest.Matchers.is(true));1021 Assert.assertThat(captured.properties.get("prop6"), org.hamcrest.Matchers.nullValue());1022 // 110 props of 300 bytes should be enough to make the event fail.1023 properties.clear();1024 for (int i = 0; i < 110; ++i) {1025 properties.put(new String(new char[300]).replace('\0', 'a') + i ,1026 new String(new char[300]).replace('\0', 'a') + i);1027 }1028 Assert.assertThat(client.track("key1", "user", "purchase", properties), org.hamcrest.Matchers.is(false));1029 }1030 @Test1031 public void client_cannot_perform_actions_when_destroyed() throws InterruptedException, URISyntaxException, TimeoutException, IOException {1032 String test = "split";1033 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1034 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1035 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);1036 SDKReadinessGates gates = mock(SDKReadinessGates.class);1037 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1038 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1039 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);1040 SplitFactory mockFactory = new SplitFactory() {1041 private boolean destroyed = false;1042 @Override1043 public SplitClient client() { return null; }1044 @Override1045 public SplitManager manager() { return null; }1046 @Override1047 public void destroy() { destroyed = true; }1048 @Override1049 public boolean isDestroyed() { return destroyed; }1050 };1051 SplitClientImpl client = new SplitClientImpl(1052 mockFactory,1053 splitCacheConsumer,1054 new ImpressionsManager.NoOpImpressionsManager(),1055 NoopEventsStorageImp.create(),1056 config,1057 gates,1058 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1059 );1060 Assert.assertThat(client.getTreatment("valid", "split"),1061 org.hamcrest.Matchers.is(org.hamcrest.Matchers.not(Treatments.CONTROL)));1062 Assert.assertThat(client.track("validKey", "valid_traffic_type", "valid_event"),1063 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(true)));1064 client.destroy();1065 Assert.assertThat(client.getTreatment("valid", "split"),1066 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(Treatments.CONTROL)));1067 Assert.assertThat(client.track("validKey", "valid_traffic_type", "valid_event"),1068 org.hamcrest.Matchers.is(org.hamcrest.Matchers.equalTo(false)));1069 }1070 @Test1071 public void worksAndHasConfigTryKetTreatmentWithKey() {1072 String test = "test1";1073 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1074 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1075 // Add config for only one treatment1076 Map<String, String> configurations = new HashMap<>();1077 configurations.put(Treatments.ON, "{\"size\" : 30}");1078 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1, configurations);1079 SDKReadinessGates gates = mock(SDKReadinessGates.class);1080 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1081 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1082 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);1083 SplitClientImpl client = new SplitClientImpl(1084 mock(SplitFactory.class),1085 splitCacheConsumer,1086 new ImpressionsManager.NoOpImpressionsManager(),1087 NoopEventsStorageImp.create(),1088 config,1089 gates,1090 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1091 );1092 int numKeys = 5;1093 for (int i = 0; i < numKeys; i++) {1094 Map<String, Object> attributes = new HashMap<>();1095 String randomKey = RandomStringUtils.random(10);1096 Key key = new Key(randomKey, "BucketingKey");1097 assertThat(client.getTreatment(randomKey, test), is(equalTo("on")));1098 assertThat(client.getTreatmentWithConfig(key, test, attributes).config(), is(equalTo(configurations.get("on"))));1099 }1100 // Times 2 because we are calling getTreatment twice. Once for getTreatment and one for getTreatmentWithConfig1101 verify(splitCacheConsumer, times(numKeys * 2)).get(test);1102 }1103 @Test(expected = IllegalArgumentException.class)1104 public void blockUntilReadyException() throws TimeoutException, InterruptedException {1105 String test = "test1";1106 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1107 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1108 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);1109 SDKReadinessGates gates = mock(SDKReadinessGates.class);1110 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1111 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1112 when(splitCacheConsumer.get(test)).thenReturn(parsedSplit);1113 SplitClientConfig config = SplitClientConfig.builder().setBlockUntilReadyTimeout(-100).build();1114 SplitClientImpl client = new SplitClientImpl(1115 mock(SplitFactory.class),1116 splitCacheConsumer,1117 new ImpressionsManager.NoOpImpressionsManager(),1118 NoopEventsStorageImp.create(),1119 config,1120 gates,1121 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1122 );1123 client.blockUntilReady();1124 }1125 @Test1126 public void null_key_results_in_control_getTreatments() {1127 String test = "test1";1128 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1129 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1130 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);1131 Map<String, ParsedSplit> splits = new HashMap<>();1132 splits.put(test, parsedSplit);1133 SDKReadinessGates gates = mock(SDKReadinessGates.class);1134 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1135 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1136 when(splitCacheConsumer.fetchMany(Collections.singletonList(test))).thenReturn(splits);1137 SplitClientImpl client = new SplitClientImpl(1138 mock(SplitFactory.class),1139 splitCacheConsumer,1140 new ImpressionsManager.NoOpImpressionsManager(),1141 NoopEventsStorageImp.create(),1142 config,1143 gates,1144 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1145 );1146 assertEquals(Treatments.CONTROL, client.getTreatments(null, Collections.singletonList("test1")).get("test1"));1147 verifyZeroInteractions(splitCacheConsumer);1148 }1149 @Test1150 public void null_splits_results_in_empty_getTreatments() {1151 String test = "test1";1152 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1153 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1154 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);1155 Map<String, ParsedSplit> splits = new HashMap<>();1156 splits.put(test, parsedSplit);1157 SDKReadinessGates gates = mock(SDKReadinessGates.class);1158 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1159 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1160 when(splitCacheConsumer.fetchMany(Collections.singletonList(test))).thenReturn(splits);1161 SplitClientImpl client = new SplitClientImpl(1162 mock(SplitFactory.class),1163 splitCacheConsumer,1164 new ImpressionsManager.NoOpImpressionsManager(),1165 NoopEventsStorageImp.create(),1166 config,1167 gates,1168 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1169 );1170 assertEquals(0, client.getTreatments("key", null).size());1171 verifyZeroInteractions(splitCacheConsumer);1172 }1173 @Test1174 public void exceptions_result_in_control_getTreatments() {1175 SDKReadinessGates gates = mock(SDKReadinessGates.class);1176 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1177 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1178 when(splitCacheConsumer.fetchMany(anyList())).thenThrow(RuntimeException.class);1179 SplitClientImpl client = new SplitClientImpl(1180 mock(SplitFactory.class),1181 splitCacheConsumer,1182 new ImpressionsManager.NoOpImpressionsManager(),1183 NoopEventsStorageImp.create(),1184 config,1185 gates,1186 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1187 );1188 Map<String, String> result = client.getTreatments("adil@relateiq.com", Arrays.asList("test1", "test2"));1189 assertEquals(2, result.values().size());1190 assertEquals(Treatments.CONTROL, result.get("test1"));1191 assertEquals(Treatments.CONTROL, result.get("test2"));1192 verify(splitCacheConsumer).fetchMany(anyList());1193 }1194 @Test1195 public void getTreatments_works() {1196 String test = "test1";1197 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1198 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1199 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);1200 Map<String, ParsedSplit> splits = new HashMap<>();1201 splits.put(test, parsedSplit);1202 SDKReadinessGates gates = mock(SDKReadinessGates.class);1203 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1204 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1205 when(splitCacheConsumer.fetchMany(anyList())).thenReturn(splits);1206 when(gates.isSDKReady()).thenReturn(true);1207 SplitClientImpl client = new SplitClientImpl(1208 mock(SplitFactory.class),1209 splitCacheConsumer,1210 new ImpressionsManager.NoOpImpressionsManager(),1211 NoopEventsStorageImp.create(),1212 config,1213 gates,1214 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1215 );1216 Map<String, String> result = client.getTreatments("randomKey", Arrays.asList(test, "test2"));1217 assertEquals("on", result.get(test));1218 assertEquals(Treatments.CONTROL, result.get("test2"));1219 verify(TELEMETRY_STORAGE, times(1)).recordLatency(Mockito.anyObject(), Mockito.anyLong());1220 }1221 @Test1222 public void empty_splits_results_in_null_getTreatments() {1223 String test = "test1";1224 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1225 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1226 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);1227 Map<String, ParsedSplit> splits = new HashMap<>();1228 splits.put(test, parsedSplit);1229 SDKReadinessGates gates = mock(SDKReadinessGates.class);1230 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1231 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1232 when(splitCacheConsumer.fetchMany(Collections.singletonList(test))).thenReturn(splits);1233 SplitClientImpl client = new SplitClientImpl(1234 mock(SplitFactory.class),1235 splitCacheConsumer,1236 new ImpressionsManager.NoOpImpressionsManager(),1237 NoopEventsStorageImp.create(),1238 config,1239 gates,1240 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1241 );1242 Map<String, String> result = client.getTreatments("key", new ArrayList<>());1243 assertNotNull(result);1244 assertTrue(result.isEmpty());1245 verifyZeroInteractions(splitCacheConsumer);1246 }1247 @Test1248 public void exceptions_result_in_control_treatments() {1249 SDKReadinessGates gates = mock(SDKReadinessGates.class);1250 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1251 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1252 when(splitCacheConsumer.get(anyString())).thenThrow(RuntimeException.class);1253 SplitClientImpl client = new SplitClientImpl(1254 mock(SplitFactory.class),1255 splitCacheConsumer,1256 new ImpressionsManager.NoOpImpressionsManager(),1257 NoopEventsStorageImp.create(),1258 config,1259 gates,1260 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1261 );1262 Map<String, String> result = client.getTreatments("adil@relateiq.com", Arrays.asList("test1"));1263 assertEquals(1, result.size());1264 assertEquals(Treatments.CONTROL, result.get("test1"));1265 }1266 @Test1267 public void works_treatments() {1268 String test = "test1";1269 String test2 = "test2";1270 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1271 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1272 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);1273 ParsedSplit parsedSplit2 = ParsedSplit.createParsedSplitForTests(test2, 123, false, Treatments.OFF, conditions, null, 1, 1);1274 Map<String, ParsedSplit> parsedSplits = new HashMap<>();1275 parsedSplits.put(test, parsedSplit);1276 parsedSplits.put(test2, parsedSplit2);1277 SDKReadinessGates gates = mock(SDKReadinessGates.class);1278 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1279 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1280 when(splitCacheConsumer.fetchMany(anyList())).thenReturn(parsedSplits);1281 when(gates.isSDKReady()).thenReturn(true);1282 SplitClientImpl client = new SplitClientImpl(1283 mock(SplitFactory.class),1284 splitCacheConsumer,1285 new ImpressionsManager.NoOpImpressionsManager(),1286 NoopEventsStorageImp.create(),1287 config,1288 gates,1289 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1290 );1291 Map<String, String> result = client.getTreatments("anyKey", Arrays.asList(test, test2));1292 assertNotNull(result);1293 assertEquals(2, result.size());1294 assertEquals("on", result.get(test));1295 assertEquals("on", result.get(test2));1296 verify(splitCacheConsumer, times(1)).fetchMany(anyList());1297 verify(TELEMETRY_STORAGE, times(1)).recordLatency(Mockito.anyObject(), Mockito.anyLong());1298 }1299 @Test1300 public void works_one_control_treatments() {1301 String test = "test1";1302 String test2 = "test2";1303 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1304 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1305 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1);1306 Map<String, ParsedSplit> parsedSplits = new HashMap<>();1307 parsedSplits.put(test, parsedSplit);1308 SDKReadinessGates gates = mock(SDKReadinessGates.class);1309 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1310 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1311 when(splitCacheConsumer.fetchMany(anyList())).thenReturn(parsedSplits);1312 when(gates.isSDKReady()).thenReturn(true);1313 SplitClientImpl client = new SplitClientImpl(1314 mock(SplitFactory.class),1315 splitCacheConsumer,1316 new ImpressionsManager.NoOpImpressionsManager(),1317 NoopEventsStorageImp.create(),1318 config,1319 gates,1320 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1321 );1322 Map<String, String> result = client.getTreatments("anyKey", Arrays.asList(test, test2));1323 assertNotNull(result);1324 assertEquals(2, result.size());1325 assertEquals("on", result.get(test));1326 assertEquals("control", result.get(test2));1327 verify(splitCacheConsumer, times(1)).fetchMany(anyList());1328 verify(TELEMETRY_STORAGE, times(1)).recordLatency(Mockito.anyObject(), Mockito.anyLong());1329 }1330 @Test1331 public void treatments_worksAndHasConfig() {1332 String test = "test1";1333 String test2 = "test2";1334 ParsedCondition rollOutToEveryone = ParsedCondition.createParsedConditionForTests(CombiningMatcher.of(new AllKeysMatcher()), Lists.newArrayList(partition("on", 100)));1335 List<ParsedCondition> conditions = Lists.newArrayList(rollOutToEveryone);1336 // Add config for only one treatment1337 Map<String, String> configurations = new HashMap<>();1338 configurations.put(Treatments.ON, "{\"size\" : 30}");1339 configurations.put(Treatments.CONTROL, "{\"size\" : 30}");1340 ParsedSplit parsedSplit = ParsedSplit.createParsedSplitForTests(test, 123, false, Treatments.OFF, conditions, null, 1, 1, configurations);1341 Map<String, ParsedSplit> parsedSplits = new HashMap<>();1342 parsedSplits.put(test, parsedSplit);1343 SDKReadinessGates gates = mock(SDKReadinessGates.class);1344 SplitCacheConsumer splitCacheConsumer = mock(SplitCacheConsumer.class);1345 SegmentCacheConsumer segmentCacheConsumer = mock(SegmentCacheConsumer.class);1346 when(splitCacheConsumer.fetchMany(anyList())).thenReturn(parsedSplits);1347 SplitClientImpl client = new SplitClientImpl(1348 mock(SplitFactory.class),1349 splitCacheConsumer,1350 new ImpressionsManager.NoOpImpressionsManager(),1351 NoopEventsStorageImp.create(),1352 config,1353 gates,1354 new EvaluatorImp(splitCacheConsumer, segmentCacheConsumer), TELEMETRY_STORAGE, TELEMETRY_STORAGE1355 );1356 Map<String, Object> attributes = new HashMap<>();1357 Map<String, SplitResult> result = client.getTreatmentsWithConfig("randomKey", Arrays.asList(test, test2, "", null), attributes);1358 assertEquals(2, result.size());1359 assertEquals(configurations.get("on"), result.get(test).config());1360 assertNull(result.get(test2).config());...

Full Screen

Full Screen

Source:Cortado_Tests.java Github

copy

Full Screen

...39 assertThat(matcher).isNotInstanceOf(Matching.class);40 }41 @Order(4)42 @Test43 public void view_withCondition_thenAnd_doesNotImplementMatcher_implementsMatching() {44 final Unfinished.And.Matcher matcher = Cortado.view().withText("test").and();45 assertThat(matcher).isNotInstanceOf(org.hamcrest.Matcher.class);46 assertThat(matcher).isInstanceOf(Matching.class);47 }48 @Order(5)49 @Test50 public void view_withCondition_thenAnd_thenNot_doesNotImplementMatcher_implementsMatching() {51 final Negated.Unfinished.And.Matcher matcher = Cortado.view().withText("test").and().not();52 assertThat(matcher).isNotInstanceOf(org.hamcrest.Matcher.class);53 assertThat(matcher).isInstanceOf(Matching.class);54 }55 @Order(6)56 @Test57 public void view_withCondition_thenAnd_thenCondition_implementsMatcher_doesNotImplementMatching() {58 final Cortado.And.Matcher matcher = Cortado.view().withText("test").and().withHint("test");59 assertThat(matcher).isInstanceOf(org.hamcrest.Matcher.class);60 assertThat(matcher).isNotInstanceOf(Matching.class);61 }62 @Order(7)63 @Test64 public void view_withCondition_thenAnd_thenNot_thenCondition_implementsMatcher_doesNotImplementMatching() {65 final Cortado.And.Matcher matcher = Cortado.view().withText("test").and().not().withHint("test");66 assertThat(matcher).isInstanceOf(org.hamcrest.Matcher.class);67 assertThat(matcher).isNotInstanceOf(Matching.class);68 }69 @Order(8)70 @Test71 public void view_withCondition_thenOr_doesNotImplementMatcher_implementsMatching() {72 final Unfinished.Or.Matcher matcher = Cortado.view().withText("test").or();73 assertThat(matcher).isNotInstanceOf(org.hamcrest.Matcher.class);74 assertThat(matcher).isInstanceOf(Matching.class);75 }76 @Order(9)77 @Test78 public void view_withCondition_thenOr_thenNot_doesNotImplementMatcher_implementsMatching() {79 final Negated.Unfinished.Or.Matcher matcher = Cortado.view().withText("test").or().not();80 assertThat(matcher).isNotInstanceOf(org.hamcrest.Matcher.class);81 assertThat(matcher).isInstanceOf(Matching.class);82 }83 @Order(10)84 @Test85 public void view_withCondition_thenOr_thenCondition_implementsMatcher_doesNotImplementMatching() {86 final Cortado.Or.Matcher matcher = Cortado.view().withText("test").or().withHint("test");87 assertThat(matcher).isInstanceOf(org.hamcrest.Matcher.class);88 assertThat(matcher).isNotInstanceOf(Matching.class);89 }90 @Order(11)91 @Test92 public void view_withCondition_thenOr_thenNot_thenCondition_implementsMatcher_doesNotImplementMatching() {93 final Cortado.Or.Matcher matcher = Cortado.view().withText("test").or().not().withHint("test");94 assertThat(matcher).isInstanceOf(org.hamcrest.Matcher.class);95 assertThat(matcher).isNotInstanceOf(Matching.class);96 }97 // onView98 @Order(12)99 @Test100 public void onView_doesNotImplementInteractable_implementsMatching() {101 final Start.ViewInteraction interaction = Cortado.onView();102 assertThat(interaction).isNotInstanceOf(Interactable.class);103 assertThat(interaction).isInstanceOf(Matching.class);104 }105 @Order(13)106 @Test107 public void onView_thenNot_doesNotImplementInteractable_implementsMatching() {108 final Negated.Start.ViewInteraction interaction = Cortado.onView().not();109 assertThat(interaction).isNotInstanceOf(Interactable.class);110 assertThat(interaction).isInstanceOf(Matching.class);111 }112 @Order(14)113 @Test114 public void onView_withSingleCondition_implementsInteractable_doesNotImplementMatching() {115 final Cortado.OrAnd.ViewInteraction interaction = Cortado.onView().withText("test");116 assertThat(interaction).isInstanceOf(Interactable.class);117 assertThat(interaction).isNotInstanceOf(Matching.class);118 }119 @Order(15)120 @Test121 public void onView_withCondition_thenAnd_doesNotImplementInteractable_implementsMatching() {122 final Unfinished.And.ViewInteraction interaction = Cortado.onView().withText("test").and();123 assertThat(interaction).isNotInstanceOf(Interactable.class);124 assertThat(interaction).isInstanceOf(Matching.class);125 }126 @Order(16)127 @Test128 public void onView_withCondition_thenAnd_thenNot_doesNotImplementInteractable_implementsMatching() {129 final Negated.Unfinished.And.ViewInteraction interaction = Cortado.onView().withText("test").and().not();130 assertThat(interaction).isNotInstanceOf(Interactable.class);131 assertThat(interaction).isInstanceOf(Matching.class);132 }133 @Order(17)134 @Test135 public void onView_withCondition_thenAnd_thenCondition_implementsInteractable_doesNotImplementMatching() {136 final Cortado.And.ViewInteraction interaction = Cortado.onView().withText("test").and().withHint("test");137 assertThat(interaction).isInstanceOf(Interactable.class);138 assertThat(interaction).isNotInstanceOf(Matching.class);139 }140 @Order(18)141 @Test142 public void onView_withCondition_thenAnd_thenNot_thenCondition_implementsInteractable_doesNotImplementMatching() {143 final Cortado.And.ViewInteraction interaction = Cortado.onView().withText("test").and().not().withHint("test");144 assertThat(interaction).isInstanceOf(Interactable.class);145 assertThat(interaction).isNotInstanceOf(Matching.class);146 }147 @Order(19)148 @Test149 public void onView_withCondition_thenOr_doesNotImplementInteractable_implementsMatching() {150 final Unfinished.Or.ViewInteraction interaction = Cortado.onView().withText("test").or();151 assertThat(interaction).isNotInstanceOf(Interactable.class);152 assertThat(interaction).isInstanceOf(Matching.class);153 }154 @Order(20)155 @Test156 public void onView_withCondition_thenOr_thenNot_doesNotImplementInteractable_implementsMatching() {157 final Negated.Unfinished.Or.ViewInteraction interaction = Cortado.onView().withText("test").or().not();158 assertThat(interaction).isNotInstanceOf(Interactable.class);159 assertThat(interaction).isInstanceOf(Matching.class);160 }161 @Order(21)162 @Test163 public void onView_withCondition_thenOr_thenCondition_implementsInteractable_doesNotImplementMatching() {164 final Cortado.Or.ViewInteraction interaction = Cortado.onView().withText("test").or().withHint("test");165 assertThat(interaction).isInstanceOf(Interactable.class);166 assertThat(interaction).isNotInstanceOf(Matching.class);167 }168 @Order(21)169 @Test170 public void onView_withCondition_thenOr_thenNot_thenCondition_implementsInteractable_doesNotImplementMatching() {171 final Cortado.Or.ViewInteraction interaction = Cortado.onView().withText("test").or().not().withHint("test");172 assertThat(interaction).isInstanceOf(Interactable.class);173 assertThat(interaction).isNotInstanceOf(Matching.class);174 }175 // setting linkers176 @Test177 public void view_hasProperLinker_initially() {178 //given179 Start.Matcher view = Cortado.view();180 //when181 Cortado.OrAnd.Matcher beforeAnd = view.withText("test");182 //then183 assertThat(beforeAnd.getCortado().linker).isEqualTo(Linker.REGULAR);184 }185 @Test186 public void view_and_setsProperLinker() {187 //given188 Cortado.OrAnd.Matcher beforeAnd = Cortado.view().withText("test");189 //when190 Unfinished.And.Matcher afterAnd = beforeAnd.and();191 //then192 assertThat(afterAnd.getCortado().linker).isEqualTo(Linker.AND);193 }194 @Test195 public void view_or_setsProperLinker() {196 //given197 Cortado.OrAnd.Matcher beforeOr = Cortado.view().withText("test");198 //when199 Unfinished.Or.Matcher afterOr = beforeOr.or();200 //then201 assertThat(afterOr.getCortado().linker).isEqualTo(Linker.OR);202 }203 @Test204 public void onView_hasProperLinker_initially() {205 //given206 Start.ViewInteraction viewInteraction = Cortado.onView();207 //when208 Cortado.OrAnd.ViewInteraction beforeAnd = viewInteraction.withText("test");209 //then210 assertThat(beforeAnd.getCortado().linker).isEqualTo(Linker.REGULAR);211 }212 @Test213 public void onView_and_setsProperLinker() {214 //given215 Cortado.OrAnd.ViewInteraction beforeAnd = Cortado.onView().withText("test");216 //when217 Unfinished.And.ViewInteraction afterAnd = beforeAnd.and();218 //then219 assertThat(afterAnd.getCortado().linker).isEqualTo(Linker.AND);220 }221 @Test222 public void onView_or_setsProperLinker() {223 //given224 Cortado.OrAnd.ViewInteraction beforeOr = Cortado.onView().withText("test");225 //when226 Unfinished.Or.ViewInteraction afterOr = beforeOr.or();227 //then228 assertThat(afterOr.getCortado().linker).isEqualTo(Linker.OR);229 }230 // negated constructors231 @Test232 public void view_hasProperNegatedFlag_initially() {233 //given234 //when235 Start.Matcher view = Cortado.view();236 //then237 assertThat(view.getCortado().negateNextMatcher).isFalse();238 }239 @Test240 public void view_not_setsNegatedFlag() {241 //given242 Start.Matcher view = Cortado.view();243 //when244 Negated.Start.Matcher not = view.not();245 //then246 assertThat(not.getCortado().negateNextMatcher).isTrue();247 }248 @Test249 public void view_withCondition_hasProperNegatedFlag() {250 //given251 //when252 Cortado.OrAnd.Matcher matcher = Cortado.view().withText("test");253 //then254 assertThat(matcher.getCortado().negateNextMatcher).isFalse();255 }256 @Test257 public void view_withCondition_or_not_setsNegatedFlag() {258 //given259 Cortado.OrAnd.Matcher matcher = Cortado.view().withText("test");260 //when261 Negated.Unfinished.Or.Matcher not = matcher.or().not();262 //then263 assertThat(not.getCortado().negateNextMatcher).isTrue();264 }265 @Test266 public void view_withCondition_and_not_setsNegatedFlag() {267 //given268 Cortado.OrAnd.Matcher matcher = Cortado.view().withText("test");269 //when270 Negated.Unfinished.And.Matcher not = matcher.and().not();271 //then272 assertThat(not.getCortado().negateNextMatcher).isTrue();273 }274 @Test275 public void onView_hasProperNegatedFlag_initially() {276 //given277 //when278 Start.ViewInteraction viewInteraction = Cortado.onView();279 //then280 assertThat(viewInteraction.getCortado().negateNextMatcher).isFalse();281 }282 @Test283 public void onView_not_setsNegatedFlag() {284 //given285 Start.ViewInteraction viewInteraction = Cortado.onView();286 //when287 Negated.Start.ViewInteraction not = viewInteraction.not();288 //then289 assertThat(not.getCortado().negateNextMatcher).isTrue();290 }291 @Test292 public void onView_withCondition_hasProperNegatedFlag() {293 //given294 //when295 Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onView().withText("test");296 //then297 assertThat(viewInteraction.getCortado().negateNextMatcher).isFalse();298 }299 @Test300 public void onView_withCondition_or_not_setsNegatedFlag() {301 //given302 Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onView().withText("test");303 //when304 Negated.Unfinished.Or.ViewInteraction not = viewInteraction.or().not();305 //then306 assertThat(not.getCortado().negateNextMatcher).isTrue();307 }308 @Test309 public void onView_withCondition_and_not_setsNegatedFlag() {310 //given311 Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onView().withText("test");312 //when313 Negated.Unfinished.And.ViewInteraction not = viewInteraction.and().not();314 //then315 assertThat(not.getCortado().negateNextMatcher).isTrue();316 }317 // addMatcher working with negateNextWatcher318 @Test319 public void addMatcher_doesNotNegateMatcher_when_negateNextMatcher_isFalse() {320 final Start.Matcher matcher = Cortado.view();321 final Cortado cortado = matcher.getCortado();322 assertThat(cortado.matchers).hasSize(0);323 assertThat(cortado.negateNextMatcher).isFalse();324 // no matchers added, negateNextMatcher is false325 org.hamcrest.Matcher<View> viewMatcher = ViewMatchers.withText("test");326 org.hamcrest.Matcher<View> negatedViewMatcher = Matchers.not(viewMatcher);327 cortado.negateNextMatcher = false;328 cortado.addMatcher(viewMatcher);329 assertThat(cortado.matchers).hasSize(1);330 // one matcher added331 assertThat(cortado.negateNextMatcher).isFalse();332 // negateNextMatcher is still false333 final Matcher<? super View> addedMatcher = cortado.matchers.get(0);334 Utils.assertThat(addedMatcher).isEqualTo(viewMatcher);335 Utils.assertThat(addedMatcher).isNotEqualTo(negatedViewMatcher);336 }337 @Test338 public void addMatcher_negatesMatcher_when_negateNextMatcher_isTrue() {339 final Start.Matcher matcher = Cortado.view();340 final Cortado cortado = matcher.getCortado();341 assertThat(cortado.matchers).hasSize(0);342 assertThat(cortado.negateNextMatcher).isFalse();343 // no matchers added, negateNextMatcher is false344 org.hamcrest.Matcher<View> viewMatcher = ViewMatchers.withText("test");345 org.hamcrest.Matcher<View> negatedViewMatcher = Matchers.not(viewMatcher);346 cortado.negateNextMatcher = true;347 cortado.addMatcher(viewMatcher);348 assertThat(cortado.matchers).hasSize(1);349 // one matcher added350 assertThat(cortado.negateNextMatcher).isFalse();351 // negateNextMatcher is back to false352 final Matcher<? super View> addedMatcher = cortado.matchers.get(0);353 Utils.assertThat(addedMatcher).isNotEqualTo(viewMatcher);354 Utils.assertThat(addedMatcher).isEqualTo(negatedViewMatcher);355 }356 // assignableFromClass357 @Test358 public void view_returnsProperMatcher() {359 //given360 final Cortado.OrAnd.Matcher matcher = Cortado.view().withText("test");361 final Matcher<? super View> espressoMatcher = matcher.getCortado().matchers.get(0);362 //when363 //then364 Utils.assertThat(matcher).isEqualTo(espressoMatcher);365 }366 @Test367 public void textView_returnsProperMatcher() {368 //given369 final Cortado.OrAnd.Matcher matcher = Cortado.textView().withText("test");370 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(371 ViewMatchers.isAssignableFrom(TextView.class),372 matcher.getCortado().matchers.get(0));373 //when374 //then375 Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);376 }377 @Test378 public void editText_returnsProperMatcher() {379 //given380 final Cortado.OrAnd.Matcher matcher = Cortado.editText().withText("test");381 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(382 ViewMatchers.isAssignableFrom(EditText.class),383 matcher.getCortado().matchers.get(0));384 //when385 //then386 Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);387 }388 @Test389 public void button_returnsProperMatcher() {390 //given391 final Cortado.OrAnd.Matcher matcher = Cortado.button().withText("test");392 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(393 ViewMatchers.isAssignableFrom(Button.class),394 matcher.getCortado().matchers.get(0));395 //when396 //then397 Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);398 }399 @Test400 public void imageView_returnsProperMatcher() {401 //given402 final Cortado.OrAnd.Matcher matcher = Cortado.imageView().withText("test");403 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(404 ViewMatchers.isAssignableFrom(ImageView.class),405 matcher.getCortado().matchers.get(0));406 //when407 //then408 Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);409 }410 @Test411 public void imageButton_returnsProperMatcher() {412 //given413 final Cortado.OrAnd.Matcher matcher = Cortado.imageButton().withText("test");414 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(415 ViewMatchers.isAssignableFrom(ImageButton.class),416 matcher.getCortado().matchers.get(0));417 //when418 //then419 Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);420 }421 @Test422 public void onView_returnsProperViewInteraction() {423 //given424 final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onView().withText("test");425 final Matcher<? super View> espressoMatcher = viewInteraction.getCortado().matchers.get(0);426 //when427 final Matcher<View> rawMatcher = viewInteraction.getCortado().get();428 //then429 Utils.assertThat(rawMatcher).isEqualTo(espressoMatcher);430 }431 @Test432 public void onTextView_returnsProperViewInteraction() {433 //given434 final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onTextView().withText("test");435 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(436 ViewMatchers.isAssignableFrom(TextView.class),437 viewInteraction.getCortado().matchers.get(0));438 //when439 final Matcher<View> rawMatcher = viewInteraction.getCortado().get();440 //then441 Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);442 }443 @Test444 public void onEditText_returnsProperViewInteraction() {445 //given446 final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onEditText().withText("test");447 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(448 ViewMatchers.isAssignableFrom(EditText.class),449 viewInteraction.getCortado().matchers.get(0));450 //when451 final Matcher<View> rawMatcher = viewInteraction.getCortado().get();452 //then453 Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);454 }455 @Test456 public void onButton_returnsProperViewInteraction() {457 //given458 final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onButton().withText("test");459 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(460 ViewMatchers.isAssignableFrom(Button.class),461 viewInteraction.getCortado().matchers.get(0));462 //when463 final Matcher<View> rawMatcher = viewInteraction.getCortado().get();464 //then465 Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);466 }467 @Test468 public void onImageView_returnsProperViewInteraction() {469 //given470 final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onImageView().withText("test");471 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(472 ViewMatchers.isAssignableFrom(ImageView.class),473 viewInteraction.getCortado().matchers.get(0));474 //when475 final Matcher<View> rawMatcher = viewInteraction.getCortado().get();476 //then477 Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);478 }479 @Test480 public void onImageButton_returnsProperViewInteraction() {481 //given482 final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onImageButton().withText("test");483 final Matcher<View> expectedEspressoMatcher = Matchers.allOf(484 ViewMatchers.isAssignableFrom(ImageButton.class),485 viewInteraction.getCortado().matchers.get(0));486 //when487 final Matcher<View> rawMatcher = viewInteraction.getCortado().get();488 //then489 Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);490 }491}...

Full Screen

Full Screen

Source:DefaultPageDisplayConditionServiceTest.java Github

copy

Full Screen

...75 private CMSPageTypeModel productPageType;76 @Before77 public void setUp()78 {79 when(cmsItemSearchTypeBlacklistMap.get(AbstractPageModel._TYPECODE)).thenReturn(Arrays.asList(CategoryPageModel._TYPECODE));80 when(cmsAdminPageService.getAllPageTypes()).thenReturn(Arrays.asList(categoryPageType, contentPageType, productPageType));81 when(categoryPageType.getCode()).thenReturn(CategoryPageModel._TYPECODE);82 when(contentPageType.getCode()).thenReturn(ContentPageModel._TYPECODE);83 when(productPageType.getCode()).thenReturn(ProductPageModel._TYPECODE);84 }85 @Test86 public void shouldGetDisplayConditions()87 {88 when(cmsPageVariationResolverTypeRegistry.getPageVariationResolverType(ContentPageModel._TYPECODE))89 .thenReturn(Optional.<PageVariationResolverType> of(resolverType));90 when(cmsPageVariationResolverTypeRegistry.getPageVariationResolverType(ProductPageModel._TYPECODE))91 .thenReturn(Optional.<PageVariationResolverType> of(resolverType));92 when(resolverType.getResolver()).thenReturn(resolver);93 when(resolver.findDisplayConditions(ContentPageModel._TYPECODE)).thenReturn(Arrays.asList(optionData1, optionData2));94 when(resolver.findDisplayConditions(ProductPageModel._TYPECODE)).thenReturn(Arrays.asList(optionData3));95 final List<DisplayConditionData> displayConditions = displayConditionService.getDisplayConditions();96 assertThat(displayConditions, hasSize(2));97 assertThat(displayConditions, hasItem(allOf( //98 hasProperty(TYPECODE, equalTo(ContentPageModel._TYPECODE)),99 hasProperty(OPTIONS, contains(optionData1, optionData2)))));100 assertThat(displayConditions, hasItem(allOf( //101 hasProperty(TYPECODE, equalTo(ProductPageModel._TYPECODE)), hasProperty(OPTIONS, contains(optionData3)))));102 }103 @Test104 public void shouldGetDisplayConditionForTypeCode()105 {106 when(cmsPageVariationResolverTypeRegistry.getPageVariationResolverType(ContentPageModel._TYPECODE))107 .thenReturn(Optional.<PageVariationResolverType> of(resolverType));108 when(resolverType.getResolver()).thenReturn(resolver);109 when(resolver.findDisplayConditions(ContentPageModel._TYPECODE)).thenReturn(Arrays.asList(optionData1, optionData2));110 final List<OptionData> options = displayConditionService.getDisplayCondition(ContentPageModel._TYPECODE);111 assertThat(options, hasSize(2));112 assertThat(options, contains(optionData1, optionData2));113 }114 @Test115 public void shouldGetCatalogVersion_NoSupportedPageTypes() throws CMSItemNotFoundException116 {117 when(cmsAdminPageService.getAllPageTypes()).thenReturn(Collections.emptyList());118 final List<DisplayConditionData> displayConditions = displayConditionService.getDisplayConditions();119 assertThat(displayConditions, empty());120 }121}...

Full Screen

Full Screen

Source:EmployeeDaoIntTest.java Github

copy

Full Screen

...44 assertThat(newId, greaterThan(6L));45 }46 47 @Test48 public void givenExistingEmployeeNumber_then_SelectByEmployeeNumber_Return_MatchingEmployee() {49 Employee emp = employeeDao.selectByEmployeeNumber("1234567891");50 assertThat(emp, notNullValue());51 }52 @Test53 public void givenNoneExistingEmployeeNumber_then_SelectByEmployeeNumber_Return_MatchingEmployee() {54 Employee emp = employeeDao.selectByEmployeeNumber("9999999999");55 assertThat(emp, nullValue());56 }57 @Test58 public void givenNoCcondition_then_returnAll() throws Exception {59 SearchCondition cond = new SearchCondition();60 List<Employee> list = employeeDao.selectList(cond);61 assertThat(list, hasSize(6));62 }63 @Test64 public void givenNameLike_then_returnMatching() throws Exception {65 SearchCondition cond = new SearchCondition();66 cond.setNameKeyword("범");67 List<Employee> list = employeeDao.selectList(cond);68 assertThat(list, hasSize(1));69 Employee emp = list.get(0);70 assertThat(emp.getName(), equalTo("최범균"));71 }72 @Test73 public void givenEmpNumber_then_returnMatching() throws Exception {74 SearchCondition cond = new SearchCondition();75 cond.setEmpNumber("1234567891");76 List<Employee> list = employeeDao.selectList(cond);77 assertThat(list, hasSize(1));78 Employee emp = list.get(0);79 assertThat(emp.getName(), equalTo("홍길동"));80 }81 @Test82 public void givenFromJoinedDate_then_returnMatching() throws Exception {83 SearchCondition cond = new SearchCondition();84 cond.setFromJoinedDate(createDate("2013-01-01"));85 List<Employee> list = employeeDao.selectList(cond);86 assertThat(list, hasSize(5));87 }88 @Test89 public void givenToJoinedDate_then_returnMatching() throws Exception {90 SearchCondition cond = new SearchCondition();91 cond.setFromJoinedDate(createDate("2013-12-31"));92 List<Employee> list = employeeDao.selectList(cond);93 assertThat(list, hasSize(3));94 }95 @Test96 public void givenFromTo_then_returnMathcing() throws Exception {97 SearchCondition cond = new SearchCondition();98 cond.setFromJoinedDate(createDate("2013-01-01"));99 cond.setToJoinedDate(createDate("2013-12-31"));100 List<Employee> list = employeeDao.selectList(cond);101 assertThat(list, hasSize(2));102 }103 private Date createDate(String dateString) throws ParseException {104 SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");105 return format.parse(dateString);106 }107}...

Full Screen

Full Screen

Source:CheckLogicTests.java Github

copy

Full Screen

...27 @Test28 public void testCheckSingleCondition() throws Exception {29 PreCheckResultAwareCheckProcessor processor = (PreCheckResultAwareCheckProcessor) checkProcessor.getInstance();30 GeneratingResult generatingResult = mock(GeneratingResult.class);31 when(generatingResult.getText()).thenReturn("textPreGenerated");32 when(generatingResult.getCode()).thenReturn("codePreGenerated");33 when(generatingResult.getInstructions()).thenReturn("instructionsPreGenerated");34 ConditionForChecking conditionForChecking = mock(ConditionForChecking.class);35 when(conditionForChecking.getId()).thenReturn(1);36 when(conditionForChecking.getTime()).thenReturn(Long.parseLong("50"));37 when(conditionForChecking.getOutput()).thenReturn("getOutput");38 when(conditionForChecking.getInput()).thenReturn("getInput");39 CheckProcessor.CheckingSingleConditionResult result = processor.checkSingleCondition(conditionForChecking, "instructions", generatingResult);40 assertThat(result.getComment(), is(not(equalTo(""))));41 assertThat(result.getResult(), is(not(equalTo(""))));42 }43}...

Full Screen

Full Screen

Source:FalseTest.java Github

copy

Full Screen

1package de.ukaachen.gpm.core.conditions;2import static org.hamcrest.CoreMatchers.instanceOf;3import static org.hamcrest.CoreMatchers.is;4import static org.hamcrest.CoreMatchers.sameInstance;5import static org.hamcrest.MatcherAssert.assertThat;6import static org.hamcrest.core.IsEqual.equalTo;7import de.ukaachen.gpm.core.model.patient.GPMPatient;8import java.util.Optional;9import org.junit.Test;10import org.junit.runner.RunWith;11import org.mockito.Mock;12import org.mockito.Mockito;13import org.mockito.junit.MockitoJUnitRunner;14@RunWith(MockitoJUnitRunner.class)15public class FalseTest {16 @Mock17 private GPMPatient patient;18 @Test19 public void testThatFalseEvaluatesToFalseAndPatientIsNotTouched() {20 // Given21 final Condition cut = False.getInstance();22 // When23 final Optional<Boolean> actual = cut.evaluate(patient);24 // Then25 assertThat(actual, is(equalTo(Optional.of(false))));26 Mockito.verifyZeroInteractions(patient);27 }28 @Test29 public void testThatNotFalseBecomesTrue() {30 // Given31 final False cut = False.getInstance();32 // When33 final Condition actual = cut.invert();34 // Then35 assertThat(actual, is(instanceOf(True.class)));36 }37 @Test38 public void testFalseTrue() {39 // Given40 final Condition theTrue = True.getInstance();41 final Condition theFalse = False.getInstance();42 // When43 final Condition and = theFalse.and(theTrue);44 final Condition or = theFalse.or(theTrue);45 // Then46 assertThat(and.evaluate(patient), is(equalTo(Optional.of(false))));47 assertThat(or.evaluate(patient), is(equalTo(Optional.of(true))));48 }49 @Test50 public void testFalseFalse() {51 // Given52 final Condition theFalse1 = False.getInstance();53 final Condition theFalse2 = False.getInstance();54 // When55 final Condition or = theFalse1.or(theFalse2);56 final Condition and = theFalse1.and(theFalse2);57 // Then58 assertThat(or.evaluate(patient), is(equalTo(Optional.of(false))));59 assertThat(and.evaluate(patient), is(equalTo(Optional.of(false))));60 assertThat(theFalse1, is(sameInstance(theFalse2)));61 }62}...

Full Screen

Full Screen

Source:TrueTest.java Github

copy

Full Screen

1package de.ukaachen.gpm.core.conditions;2import static org.hamcrest.CoreMatchers.instanceOf;3import static org.hamcrest.CoreMatchers.is;4import static org.hamcrest.CoreMatchers.sameInstance;5import static org.hamcrest.MatcherAssert.assertThat;6import static org.hamcrest.core.IsEqual.equalTo;7import de.ukaachen.gpm.core.model.patient.GPMPatient;8import java.util.Optional;9import org.junit.Test;10import org.junit.runner.RunWith;11import org.mockito.Mock;12import org.mockito.Mockito;13import org.mockito.junit.MockitoJUnitRunner;14@RunWith(MockitoJUnitRunner.class)15public class TrueTest {16 @Mock17 private GPMPatient patient;18 @Test19 public void testThatTrueEvaluatesToTrueAndPatientIsNotTouched() {20 // Given21 final True cut = True.getInstance();22 // When23 final Optional<Boolean> actual = cut.evaluate(patient);24 // Then25 assertThat(actual, is(equalTo(Optional.of(true))));26 Mockito.verifyZeroInteractions(patient);27 }28 @Test29 public void testThatNotTrueBecomesFalse() {30 // Given31 final True cut = True.getInstance();32 // When33 final Condition actual = cut.invert();34 // Then35 assertThat(actual, is(instanceOf(False.class)));36 }37 @Test38 public void testTrueFalse() {39 // Given40 final True theTrue = True.getInstance();41 final Condition theFalse = False.getInstance();42 // When43 final Condition and = theTrue.and(theFalse);44 final Condition or = theTrue.or(theFalse);45 // Then46 assertThat(and.evaluate(patient), is(equalTo(Optional.of(false))));47 assertThat(or.evaluate(patient), is(equalTo(Optional.of(true))));48 }49 @Test50 public void testTrueTrue() {51 // Given52 final True theTrue1 = True.getInstance();53 final True theTrue2 = True.getInstance();54 // When55 final Condition or = theTrue1.or(theTrue2);56 final Condition and = theTrue1.and(theTrue2);57 // Then58 assertThat(and.evaluate(patient), is(equalTo(Optional.of(true))));59 assertThat(or.evaluate(patient), is(equalTo(Optional.of(true))));60 assertThat(theTrue1, is(sameInstance(theTrue2)));61 }62}...

Full Screen

Full Screen

Source:Condition.java Github

copy

Full Screen

2 public static final org.hamcrest.Condition$NotMatched<java.lang.Object> NOT_MATCHED;3 public abstract boolean matching(org.hamcrest.Matcher<T>, java.lang.String);4 public abstract <U> org.hamcrest.Condition<U> and(org.hamcrest.Condition$Step<? super T, U>);5 public final boolean matching(org.hamcrest.Matcher<T>);6 public final <U> org.hamcrest.Condition<U> then(org.hamcrest.Condition$Step<? super T, U>);7 public static <T> org.hamcrest.Condition<T> notMatched();8 public static <T> org.hamcrest.Condition<T> matched(T, org.hamcrest.Description);9 org.hamcrest.Condition(org.hamcrest.Condition$1);10 static {};11}...

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.MatcherAssert.assertThat;2import static org.hamcrest.Matchers.is;3import static org.hamcrest.Matchers.notNullValue;4import static org.hamcrest.core.IsEqual.equalTo;5import static org.hamcrest.core.IsNot.not;6import org.hamcrest.Condition;7import org.junit.Test;8public class ConditionExampleTest {9 public void testCondition() {10 assertThat(1, is(equalTo(1)));11 assertThat(1, is(not(equalTo(2))));12 assertThat(1, is(notNullValue()));13 assertThat(1, is(not(notNullValue())));14 assertThat(1, is(new Condition<Integer>() {15 public boolean matches(Integer value) {16 return value == 1;17 }18 }));19 }20}21Junit: How to use assertThat() method of org.hamcrest.MatcherAssert class?22Junit: How to use assertThat() method of org.hamcrest.MatcherAssert class? Junit: How to use assertArrayEquals() method of org.junit.Assert class?

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.MatcherAssert.assertThat;2import static org.hamcrest.Matchers.*;3import static org.hamcrest.core.Is.is;4import static org.hamcrest.core.IsNot.not;5import org.hamcrest.Condition;6import org.junit.Test;7public class ConditionTest {8 public void testCondition() {9 Condition<String> condition = new Condition<String>() {10 public boolean matches(String value) {11 return value.startsWith("J");12 }13 };14 assertThat("Java", condition);15 assertThat("Kotlin", not(condition));16 }17}18import static org.hamcrest.MatcherAssert.assertThat;19import static org.hamcrest.Matchers.*;20import static org.hamcrest.core.Is.is;21import static org.hamcrest.core.IsNot.not;22import org.hamcrest.Condition;23import org.junit.Test;24public class ConditionTest {25 public void testCondition() {26 Condition<String> condition = new Condition<String>() {27 public boolean matches(String value) {28 return value.startsWith("J");29 }30 };31 assertThat("Java", condition);32 assertThat("Kotlin", not(condition));33 }34}

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.Condition2import org.hamcrest.Matcher3import org.hamcrest.MatcherAssert.assertThat.assertThat4import org.hamcrest.Matchers.equalTo5def condition = new Condition() {6 boolean matches(Object o) {7 }8 String toString() {9 }10}11assertThat(condition, new Matcher() {12 boolean matches(Object o) {13 return (Boolean) o14 }15 void describeTo(Description description) {16 description.appendText("matches 'foo'")17 }18})19assertThat(condition, equalTo(true))20assertThat(condition, new Matcher() {21 boolean matches(Object o) {22 return (Boolean) o23 }24 void describeMismatch(Object item, Description description) {25 description.appendText("does not match 'foo'")26 }27 void describeTo(Description description) {28 description.appendText("matches 'foo'")29 }30})31assertThat(condition, equalTo(true))32assertThat(condition, new Matcher() {33 boolean matches(Object o) {34 return (Boolean) o35 }36 void describeMisatch(Object item, Description description) {37 description.appendText("does not match 'foo'")38 }39 void describeTo(Description description) {40 descritin.appendText("matches 'foo'")41 }42})43asseThat(condition,equalT(tue))44assertThat(condition, new Matcher() {45 boolean matches(Object o) {46 return (Boolean) o47 }48 void describeMismatch(Object item, Description description) {49 description.appendText("does not match 'foo'")50 }51 void describeTo(Description description) {52 description.appendText("matches 'foo'")53 }54})55assertThat(condition, equalTo(true))56assertThat(condition, new Matcher() {57 boolean matches(Object o) {58 return (Boolean) o59 }60 void describeMismatch(Object item, Description description) {61 description.appendText("does not match 'foo'")62 }63 void describeTo(Description description) {64 description.appendText("matches 'foo'")65 }66})67assertThat(condition, equalTo(true))68assertThat(condition, new Matcher

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.Condition2import org.hamcrest.Matcher3import org.hamcrest.MatcherAssert4import org.hamcrest.Matchers5import or6def condition = new Condition() {7 boolean matches(Object o) {8 }9 String toString() {10 }11}12assertThat(condition, new Matcher() {13 boolean matches(Object o) {14 return (Boolean) o15 }16 void describeTo(Description description) {17 description.appendText("matches 'foo'")18 }19})20assertThat(condition, equalTo(true))21assertThat(condition, new Matcher() {22 boolean matches(Object o) {23 return (Boolean) o24 }25 void describeMismatch(Object item, Description description) {26 description.appendText("does not match 'foo'")27 }28 void describeTo(Description description) {29 description.appendText("matches 'foo'")30 }31})32assertThat(condition, equalTo(true))33assertThat(condition, new Matcher() {34 boolean matches(Object o) {35 return (Boolean) o36 }37 void describeMismatch(Object item, Description description) {38 description.appendText("does not match 'foo'")39 }40 void describeTo(Description description) {41 description.appendText("matches 'foo'")42 }43})44assertThat(condition, equalTo(true))45assertThat(condition, new Matcher() {46 boolean matches(Object o) {47 return (Boolean) o48 }49 void describeMismatch(Object item, Description description) {50 description.appendText("does not match 'foo'")51 }52 void describeTo(Description description) {53 description.appendText("matches 'foo'")54 }55})56assertThat(condition, equalTo(true))57assertThat(condition, new Matcher() {58 boolean matches(Object o) {59 return (Boolean) o60 }61 void describeMismatch(Object item, Description description) {62 description.appendText("does not match 'foo'")63 }64 void describeTo(Description description) {65 description.appendText("matches 'foo'")66 }67})68assertThat(condition, equalTo(true))69assertThat(condition, new Matcher

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.Condition2import org.hamcrest.Matcher3import org.hamcrest.MatcherAssert4import org.hamcrest.Matchers5import org.hamcrest.core.Is6import org.hamcrest.core.IsEqual7def "test then method"() {8 def condition = new Condition({ it > 0 }, "positive")9 def matcher = condition.then(Matchers.lessThan(1))10 MatcherAssert.assertThat(0, matcher)11}12import org.hamcrest.Condition13import org.hamcrest.Matcher14import org.hamcrest.MatcherAssert15import org.hamcrest.Matchers16import org.hamcrest.core.Is17import org.hamcrest.core.IsEqual18def "test then method"() {19 def condition = new Condition({ it > 0 }, "positive")20 def matcher = condition.then(Matchers.lessThan(1))21 MatcherAssert.assertThat(0, matcher)22}23import org.hamcrest.Condition24import org.hamcrest.Matcher25import org.hamcrest.MatcherAssert26import org.hamcrest.Matchers27import org.hamcrest.core.Is28import org.hamcrest.core.IsEqual29def "test then method"() {30 def condition = new Condition({ it > 0 }, "positive")31 def matcher = condition.then(Matchers.lessThan(1))32 MatcherAssert.assertThat(0, matcher)33}34import org.hamcrest.MatcherAssert35import org.hamcrest.Condition36import org.hamcrest.Matcher

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.import org.hamcrest.Mhat2import static org.hamcrest.Matchers.*3import org.hamcrest.Condition4import org.atmcrest.Description5def "test"() {6 def condicionh= new Condieion() {7 boolean matches(Object value) {8 }9 void describeTo(Description description) {10 description.appendText("is 2")11 }12 }13 assertThat(1 + 1, condition)14}

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.Condition;2import org.junit.Test;3import static org.hamcrest.MatcherAssert.assertThat;4import static org.hamcrest.Matchers.is;5public class ConditionTest {6 public void test() {7 int value = 1;8 String description = "the value is 1";9 String reason = "the value is 1";10 Condition<Integer> condition = new Condition<>(v -> v == 1, description);11 assertThat(value, condition.as("the value is 1").because(reason));12 assertThat(value, is(condition.as("the value is 1").because(reason)));13 }14}15 at org.junit.Assert.assertEquals(Assert.java:115)16 at org.junit.Assert.assertEquals(Assert.java:144)17 at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)18 at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)19 at ConditionTest.test(ConditionTest.java:21)20 at org.junit.Assert.assertEquals(Assert.java:115)21 at org.junit.Assert.assertEquals(Assert.java:144)22 at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)23 at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)24 at ConditionTest.test(ConditionTest.java:22)25package org.hamcrest;26import org.junit.Test;27import static org.hamcrest.MatcherAssert.assertThat;28import static org.hamcrest.Matchers.is;29public class ConditionTest {30 public void test() {31 int value = 1;32 String description = "the value is 1";33 String reason = "the value is 1";34 Condition<Integer> condition = new Condition<>(v -> v == 1, description);35 assertThat(value, condition.describedAs("the value is 1").because(reason));36 assertThat(value, is(condition.des37import org.hamcrest.MatcherAssert

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.MatchersCondition class2import org.hamcrest.Condition;3import org.junit.Test;4import static org.hamcrest.ssert.artThat;5import static org.hamcest.Matchers.is;6public class ConditionTest {7 public void test() {8 int value = 1;9 Sringdesription = "the vaue is 1";10 String reon = "the value i 1";11 Condition<Integer> condition = new Condition<>(v -> v == 1, description);12 assertThat(value, condition.as("the value is 1").because(reason));13 assertThat(value, is(condition.as("the value is 1").because(reason)));14 }15}16 at org.junit.Assert.assertEquals(Assert.java:115)17 at org.junit.Assert.assertEquals(Assert.java:144)18 at org.hamcrest.core.Isssert.aThat(MatcherAssert.java:20)19 at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)20 at ConditionTest.test(ConditionTest.java:21)21 at org.junit.Assert.assertEquals(Assert.java:115)22 at org.junit.Assert.assertEquals(Assert.java:144)23 at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:20)24 at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:8)25 at ConditionTest.test(ConditionTest.java:22)26package org.hamcrest;27junit.Test;28import static org.hamcrest.MatcherAssert.assertThat;29import static org.atchers.is;30public class ConditionTest {31 public void test() {32 int value = 1;33 String description = "the value is 1";34 String reason = "the value is 1";35 Condition<Integer> condition = new Condition<>(v -> v == 1, description);36 assertTh(value, ondition.describedAs("te value is 1").because(reason));37 asstThat(value, is(condition.des38def "test then method"() {39 def condition = new Condition({ it > 0 }, "positive")40 def matcher = condition.then(Matchers.lessThan(1))41 MatcherAssert.assertThat(0, matcher)42}43import org.hamcrest.Condition44import org.hamcrest.Matcher45import org.hamcrest.MatcherAssert46import org.hamcrest.Matchers47import org.hamcrest.core.Is48import org.hamcrest.core.IsEqual49def "test then method"() {50 def condition = new Condition({ it > 0 }, "positive")51 def matcher = condition.then(Matchers.lessThan(1))52 MatcherAssert.assertThat(0, matcher)53}54import org.hamcrest

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import org.hamcrest.Condition2import org.hamcrest.Matcher3def condition = new Condition('is true', { it == true })4import org.hamcrest.MatcherAssert5import org.hamcrest.Condition6import org.hamcrest.Matcher7def condition = new Condition('is true', { it == true })8import org.hamcrest.Condition9import org.hamcrest.Matcher10def condition = new Condition('is true', { it == true })11def matcher = new Matcher() {12 boolean matches(Object item) {13 condition.matches(item)14 }15 void describeTo(Description description) {16 condition.describeTo(description)17 }18}19import org.hamcrest.MatcherAssert20import org.hamcrest.Condition21import org.hamcrest.Matcher22def condition = new Condition('is true', { it == true })23def matcher = new Matcher() {24 boolean matches(Object item) {25 condition.matches(item)26 }27 void describeTo(Description description) {28 condition.describeTo(description)29 }30}31import org.hamcrest.MatcherAssert32import org.hamcrest.Condition33import org.hamcrest.Matcher34import org.hamcrest.Description35def condition = new Condition('is true', { it == true })36def matcher = new Matcher() {37 boolean matches(Object item) {38 condition.matches(item)39 }40 void describeTo(Description description) {41 condition.describeTo(description)42 }43}44import org.hamcrest.MatcherAssert45import org.hamcrest.Condition46import org.hamcrest.Matcher47import org.hamcrest.Description48def condition = new Condition('is true', { it == true })49def matcher = new Matcher() {50 boolean matches(Object item) {51 condition.matches(item)52 }53 void describeTo(Description description) {54 condition.describeTo(description)55 }56}57import org.hamcrest.MatcherAssert58import org.hamcrest.Condition59import org.hamcrest.Matcher

Full Screen

Full Screen

then

Using AI Code Generation

copy

Full Screen

1import static org.hamcrest.MatcherAssert.assertThat2import static org.hamcrest.Matchers.*3import org.hamcrest.Condition4import org.hamcrest.Description5def "test"() {6 def condition = new Condition() {7 boolean matches(Object value) {8 }9 void describeTo(Description description) {10 description.appendText("is 2")11 }12 }13 assertThat(1 + 1, condition)14}

Full Screen

Full Screen

JUnit Tutorial:

LambdaTest also has a detailed JUnit tutorial explaining its features, importance, advanced use cases, best practices, and more to help you get started with running your automation testing scripts.

JUnit Tutorial Chapters:

Here are the detailed JUnit testing chapters to help you get started:

  • Importance of Unit testing - Learn why Unit testing is essential during the development phase to identify bugs and errors.
  • Top Java Unit testing frameworks - Here are the upcoming JUnit automation testing frameworks that you can use in 2023 to boost your unit testing.
  • What is the JUnit framework
  • Why is JUnit testing important - Learn the importance and numerous benefits of using the JUnit testing framework.
  • Features of JUnit - Learn about the numerous features of JUnit and why developers prefer it.
  • JUnit 5 vs. JUnit 4: Differences - Here is a complete comparison between JUnit 5 and JUnit 4 testing frameworks.
  • Setting up the JUnit environment - Learn how to set up your JUnit testing environment.
  • Getting started with JUnit testing - After successfully setting up your JUnit environment, this chapter will help you get started with JUnit testing in no time.
  • Parallel testing with JUnit - Parallel Testing can be used to reduce test execution time and improve test efficiency. Learn how to perform parallel testing with JUnit.
  • Annotations in JUnit - When writing automation scripts with JUnit, we can use JUnit annotations to specify the type of methods in our test code. This helps us identify those methods when we run JUnit tests using Selenium WebDriver. Learn in detail what annotations are in JUnit.
  • Assertions in JUnit - Assertions are used to validate or test that the result of an action/functionality is the same as expected. Learn in detail what assertions are and how to use them while performing JUnit testing.
  • Parameterization in JUnit - Parameterized Test enables you to run the same automated test scripts with different variables. By collecting data on each method's test parameters, you can minimize time spent on writing tests. Learn how to use parameterization in JUnit.
  • Nested Tests In JUnit 5 - A nested class is a non-static class contained within another class in a hierarchical structure. It can share the state and setup of the outer class. Learn about nested annotations in JUnit 5 with examples.
  • Best practices for JUnit testing - Learn about the best practices, such as always testing key methods and classes, integrating JUnit tests with your build, and more to get the best possible results.
  • Advanced Use Cases for JUnit testing - Take a deep dive into the advanced use cases, such as how to run JUnit tests in Jupiter, how to use JUnit 5 Mockito for Unit testing, and more for JUnit testing.

JUnit Certification:

You can also check out our JUnit certification if you wish to take your career in Selenium automation testing with JUnit to the next level.

Run junit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Condition

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful