public Matcher<?> matcher(T response) throws Exception { Matcher<?>[] matchers = toHamcrestMatchers(response, matcher1, matcher2, additionalMatchers); return anyOf((Matcher<? super Object>[]) matchers); } };
/** * Await until a Atomic boolean becomes false. * * @param atomic the atomic variable * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period. */ public void untilFalse(final AtomicBoolean atomic) { untilAtomic(atomic, anyOf(is(Boolean.FALSE), is(false))); }
/** * Await until a Atomic boolean becomes true. * * @param atomic the atomic variable * @throws org.awaitility.core.ConditionTimeoutException If condition was not fulfilled within the given time period. */ public void untilTrue(final AtomicBoolean atomic) { untilAtomic(atomic, anyOf(is(Boolean.TRUE), is(true))); }
public static Matcher<Object> isJson() { return isJson(withJsonPath("$", anyOf(instanceOf(Map.class), instanceOf(List.class)))); }
private void assertFailureDuringLoad(String configXML, Class<?> expectedExceptionClass, String... expectedMessage) { try { xmlLoader.loadConfigHolder(configXML); fail("Should have failed with an exception of type: " + expectedExceptionClass.getSimpleName()); } catch (Exception e) { String message = "\nExpected: " + expectedExceptionClass.getSimpleName() + "\nActual : " + e.getClass().getSimpleName() + " with message: " + e.getMessage(); assertTrue(message, e.getClass().equals(expectedExceptionClass)); assertThat(e.getMessage(), anyOf(Arrays.stream(expectedMessage).map(Matchers::is).collect(Collectors.toList()))); } }
@Test public void shouldThrowExceptionIfRepoCanNotConnectWhenModificationCheck() throws Exception { FileUtils.deleteQuietly(repoLocation); try { git.latestModification(); fail("Should throw exception when repo cannot connected"); } catch (Exception e) { assertThat(e.getMessage(), anyOf(containsString("The remote end hung up unexpectedly"), containsString("Could not read from remote repository"))); } }
@Test @Graph( value = {"I know you"}, autoIndexNodes = false ) public void array_property() { setProperty( "I", "array1", new int[]{1, 2, 3} ); setProperty( "I", "array2", new String[]{"a", "b", "c"} ); String script = "MATCH (n) WHERE id(n) = %I% RETURN n.array1, n.array2"; String response = cypherRestCall( script, Status.OK ); assertThat( response, anyOf( containsString( "[ 1, 2, 3 ]" ), containsString( "[1,2,3]" ) ) ); assertThat( response, anyOf( containsString( "[ \"a\", \"b\", \"c\" ]" ), containsString( "[\"a\",\"b\",\"c\"]" ) ) ); }
/** * Check some general validations that all REST responses should always pass. */ public static ClientResponse sanityCheck( ClientResponse response ) { List<String> contentEncodings = response.getHeaders().get( "Content-Encoding" ); String contentEncoding; if ( contentEncodings != null && (contentEncoding = Iterables.singleOrNull( contentEncodings )) != null ) { // Specifically, this is never used for character encoding. contentEncoding = contentEncoding.toLowerCase(); assertThat( contentEncoding, anyOf( containsString( "gzip" ), containsString( "deflate" ) ) ); assertThat( contentEncoding, allOf( not( containsString( "utf-8" ) ) ) ); } return response; }
@Override @Test default void RichIterable_toArray() { Object[] array = this.newWith(3, 2, 1).toArray(); assertThat(array, anyOf( equalTo(new Object[]{1, 2, 3}), equalTo(new Object[]{1, 3, 2}), equalTo(new Object[]{2, 1, 3}), equalTo(new Object[]{2, 3, 1}), equalTo(new Object[]{3, 1, 2}), equalTo(new Object[]{3, 2, 1}))); }
@Test public void shouldThrowXsdValidationWhenSCMNamesAreDuplicate() throws Exception { String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'><scms>\n" + format(VALID_SCM_WITH_ID_NAME, "1", "scm-name") + format(VALID_SCM_WITH_ID_NAME, "2", "scm-name") + " </scms></cruise>"; try { xmlLoader.loadConfigHolder(xml); fail("should have thrown XsdValidationException"); } catch (XsdValidationException e) { assertThat(e.getMessage(), anyOf( is("Duplicate unique value [scm-name] declared for identity constraint of element \"scms\"."), is("Duplicate unique value [scm-name] declared for identity constraint \"uniqueSCMName\" of element \"scms\".") )); } }
@Test public void shouldThrowXsdValidationWhenSCMIdsAreDuplicate() throws Exception { String xml = "<cruise schemaVersion='" + GoConstants.CONFIG_SCHEMA_VERSION + "'><scms>\n" + VALID_SCM + VALID_SCM + " </scms></cruise>"; try { xmlLoader.loadConfigHolder(xml); fail("should have thrown XsdValidationException"); } catch (XsdValidationException e) { assertThat(e.getMessage(), anyOf( is("Duplicate unique value [scm-id] declared for identity constraint of element \"cruise\"."), is("Duplicate unique value [scm-id] declared for identity constraint \"uniqueSCMId\" of element \"cruise\".") )); } }
@Test @Documented( "When sending queries that\n" + "return nested results like list and maps,\n" + "these will get serialized into nested JSON representations\n" + "according to their types." ) @Graph( value = {"I know you"}, autoIndexNodes = true ) public void nested_results() throws Exception { data.get(); String script = "MATCH (n) WHERE n.name in ['I', 'you'] RETURN collect(n.name)"; String response = cypherRestCall( script, Status.OK ); Map<String,Object> resultMap = jsonToMap( response ); assertEquals( 2, resultMap.size() ); assertThat( response, anyOf( containsString( "\"I\",\"you\"" ), containsString( "\"you\",\"I\"" ), containsString( "\"I\", \"you\"" ), containsString( "\"you\", \"I\"" ) ) ); }
@Test public void shouldNotAllowConfigWithEnvironmentsWithSameNames() throws Exception { String content = configWithEnvironments( "<environments>" + " <environment name='uat' />" + " <environment name='uat' />" + "</environments>"); try { ConfigMigrator.loadWithMigration(content); fail("Should not support 2 environments with the same same"); } catch (Exception e) { assertThat(e.getMessage(), anyOf( containsString("Duplicate unique value [uat] declared for identity constraint of element \"environments\""), containsString("Duplicate unique value [uat] declared for identity constraint \"uniqueEnvironmentName\" of element \"environments\"") )); } }
@Test public void testMultiplePartitionFields() throws Exception { DatePartitionHiveVersionFinder versionFinder = new DatePartitionHiveVersionFinder(this.fs, ConfigFactory.empty()); String tableName = "VfTb3"; Table tbl = this.hiveMetastoreTestUtils.createTestAvroTable(dbName, tableName, ImmutableList.of("datepartition", "field1")); org.apache.hadoop.hive.metastore.api.Partition tp = this.hiveMetastoreTestUtils.addTestPartition(tbl, ImmutableList.of("2016-01-01-20", "f1"), (int) System.currentTimeMillis()); Partition partition = new Partition(new org.apache.hadoop.hive.ql.metadata.Table(tbl), tp); assertThat(partition.getName(), anyOf(is("field1=f1/datepartition=2016-01-01-20"), is("datepartition=2016-01-01-20/field1=f1"))); TimestampedHiveDatasetVersion dv = versionFinder.getDatasetVersion(partition); Assert.assertEquals(dv.getDateTime(), formatter.parseDateTime("2016/01/01/20")); } }
@Test public void shouldFindFirstExtensionWithImageIfPluginImplementsAtleastOneExtensionWithImage() throws Exception { Image image1 = new Image("c1", "d1", "hash1"); Image image2 = new Image("c2", "d2", "hash2"); Image image3 = new Image("c3", "d3", "hash3"); ElasticAgentPluginInfo elasticAgentPluginInfo = new ElasticAgentPluginInfo(null, null, image1, null, null); AuthorizationPluginInfo authorizationPluginInfo = new AuthorizationPluginInfo(null, null, null, image2, null); AnalyticsPluginInfo analyticsPluginInfo = new AnalyticsPluginInfo(null, image3, null, null); assertThat(new CombinedPluginInfo(elasticAgentPluginInfo).getImage(), is(image1)); assertThat(new CombinedPluginInfo(authorizationPluginInfo).getImage(), is(image2)); assertThat(new CombinedPluginInfo(analyticsPluginInfo).getImage(), is(image3)); assertThat(new CombinedPluginInfo(asList(elasticAgentPluginInfo, authorizationPluginInfo)).getImage(), anyOf(is(image1), is(image2))); assertThat(new CombinedPluginInfo(asList(analyticsPluginInfo, authorizationPluginInfo)).getImage(), anyOf(is(image2), is(image3))); }
@Test public void shouldThrowExceptionWhenPersisInvalidDom() throws Exception { //simulate the xml partial saving logic CruiseConfig cruiseConfig = ConfigMigrator.load(ConfigFileFixture.CONTAINS_MULTI_DIFFERENT_STATUS_RUN_IF); StageConfig stage = xmlLoader.fromXmlPartial(ConfigFileFixture.SAME_STATUS_RUN_IF_PARTIAL, StageConfig.class); PipelineConfig pipelineConfig = cruiseConfig.pipelineConfigByName(new CaseInsensitiveString("test")); pipelineConfig.set(0, stage); try { xmlWriter.write(cruiseConfig, output, false); fail(); } catch (Exception e) { assertThat(e.getMessage(), anyOf( is("Duplicate unique value [passed] declared for identity constraint of element \"exec\"."), is("Duplicate unique value [passed] declared for identity constraint \"uniqueRunIfTypeForExec\" of element \"exec\".") )); } }
@Test public void shouldNotAllowMultipleSCMsWithSameId() throws Exception { Configuration configuration = new Configuration(getConfigurationProperty("url", false, "http://go")); CruiseConfig configToSave = new BasicCruiseConfig(); SCM scm1 = createSCM("id", "name1", "plugin-id-1", "1.0", configuration); SCM scm2 = createSCM("id", "name2", "plugin-id-2", "1.0", configuration); configToSave.setSCMs(new SCMs(scm1, scm2)); try { xmlWriter.write(configToSave, output, false); fail("should not have allowed two SCMs with same id"); } catch (XsdValidationException e) { assertThat(e.getMessage(), anyOf( is("Duplicate unique value [id] declared for identity constraint of element \"cruise\"."), // message specific to java 10 is("Duplicate unique value [id] declared for identity constraint \"uniqueSCMId\" of element \"cruise\".") )); } }
@Test public void test1() { ClassNode cls = getClassNodeFromSmaliWithPath("loops", "TestLoopCondition5"); String code = cls.getCode().toString(); assertThat(code, anyOf(containsOne("for ("), containsOne("while (true) {"))); assertThat(code, containsOne("return -1;")); assertThat(code, countString(2, "return ")); } }
/** * Same as above but using a {@link org.hamcrest.Matcher} as the argument. */ @SuppressWarnings("unchecked") @Test public void hint_endsWith() { // This check will probably fail if the app is localized and the language is changed. Avoid // string literals in code! onView(withId(R.id.editText)).check(matches(HintMatcher.withHint(anyOf( endsWith(COFFEE_ENDING), endsWith(COFFEE_INVALID_ENDING))))); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsOne("while (true) {")); assertThat(code, anyOf(containsOne("break;"), containsOne("return;"))); assertThat(code, containsOne("throw ex;")); assertThat(code, containsOne("data.clear();")); assertThat(code, containsOne("Thread.sleep(100);")); } }