@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString("try {")); assertThat(code, containsString("Thread.sleep(1);")); assertThat(code, containsString("Thread.sleep(2);")); assertThat(code, containsString("} catch (InterruptedException e) {")); assertThat(code, containsString("} catch (Exception e2) {")); assertThat(code, not(containsString("return"))); } }
/** * A cheap test just to prove that in ASPECTJ mode, the AnnotationTransactionAspect does indeed * get loaded -- or in this case, attempted to be loaded at which point the test fails. */ @Test @SuppressWarnings("resource") public void proxyTypeAspectJCausesRegistrationOfAnnotationTransactionAspect() { try { new AnnotationConfigApplicationContext(EnableAspectjTxConfig.class, TxManagerConfig.class); fail("should have thrown CNFE when trying to load AnnotationTransactionAspect. " + "Do you actually have org.springframework.aspects on the classpath?"); } catch (Exception ex) { assertThat(ex.getMessage(), containsString("AspectJJtaTransactionManagementConfiguration")); } }
@Test @SuppressWarnings("resource") public void testInvalidConfigScopedProxy() throws Exception { exception.expect(BeanDefinitionParsingException.class); exception.expectMessage(containsString("Cannot define both 'scope-resolver' and 'scoped-proxy' on <component-scan> tag")); exception.expectMessage(containsString("Offending resource: class path resource [org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml]")); new ClassPathXmlApplicationContext("org/springframework/context/annotation/scopedProxyInvalidConfigTests.xml"); }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString("case '/':")); assertThat(code, containsString(indent(5) + "break;")); assertThat(code, containsString(indent(4) + "default:")); assertEquals(1, count(code, "i++")); assertEquals(4, count(code, "break;")); } }
@Test public void shouldReturnReadOnlyStatusWhenCreatingNodes() throws Exception { // Given HTTP.Response response = http.POST( "db/data/transaction/commit", quotedJson( "{ 'statements': [ { 'statement': 'CREATE (node)' } ] }" ) ); // Then JsonNode error = response.get( "errors" ).get( 0 ); String code = error.get( "code" ).asText(); String message = error.get( "message" ).asText(); assertEquals( "Neo.ClientError.General.ForbiddenOnReadOnlyDatabase", code ); assertThat( message, containsString( "This is a read only Neo4j instance" ) ); }
@Test public void shouldNotAllowBeginningWithDuplicateKey() throws Exception { // Given repo.begin( 1L ); // When try { repo.begin( 1L ); fail( "Should not have been able to begin." ); } catch ( ConcurrentAccessException e ) { assertThat( e.getMessage(), containsString( "Cannot begin '1', because Entry" ) ); assertThat( e.getMessage(), containsString( " with that key already exists." ) ); } }
private void assertBadAuthority(String authority, String failureMessage) throws Exception { try { useUriWithAuthority(authority); fail(failureMessage); } catch (IllegalArgumentException e) { assertThat(e.getMessage(), containsString("does not match")); } }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertEquals(5, count(code, "break;")); assertEquals(1, count(code, "System.out.println(s);")); assertEquals(1, count(code, "System.out.println(\"Not Reach\");")); assertThat(code, not(containsString("switch ((a % 4)) {"))); assertThat(code, containsString("switch (a % 4) {")); } }
@Test public void invalidScriptOutput() throws Exception { for (String badOutput : new String[] {"x", "a=b c=d", "node=b,cd", "node=b,abc,x=y"}) { try { runScriptWithOutput(badOutput); fail("Expected an exception to be thrown"); } catch (Exception e) { assertThat(e.getMessage(), containsString("Failed to parse")); assertThat(e.getMessage(), containsString(badOutput)); } } }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString("if (a1 == null) {")); assertThat(code, containsString("if (a2 != null) {")); assertThat(code, containsString("throw new AssertionError(a1 + \" != \" + a2);")); assertThat(code, not(containsString("if (a1.equals(a2)) {"))); assertThat(code, containsString("} else if (!a1.equals(a2)) {")); } }
@Test public void valueMatcher() { HttpHeaders headers = new HttpHeaders(); headers.add("foo", "bar"); HeaderAssertions assertions = headerAssertions(headers); assertions.value("foo", containsString("a")); }
@Test public void shouldReturnReadOnlyStatusWhenCreatingNodesWhichTransitivelyCreateTokens() throws Exception { // Given // When HTTP.Response response = http.POST( "db/data/transaction/commit", quotedJson( "{ 'statements': [ { 'statement': 'CREATE (node:Node)' } ] }" ) ); // Then JsonNode error = response.get( "errors" ).get( 0 ); String code = error.get( "code" ).asText(); String message = error.get( "message" ).asText(); assertEquals( "Neo.ClientError.General.ForbiddenOnReadOnlyDatabase", code ); assertThat( message, containsString( "This is a read only Neo4j instance" ) ); }
@Test public void shouldThrowConstraintViolationIfAskedToCreateCompoundConstraint() { // WHEN try ( Transaction tx = db.beginTx() ) { Schema schema = db.schema(); schema.constraintFor( label ) .assertPropertyIsUnique( "my_property_key" ) .assertPropertyIsUnique( "other_property" ).create(); tx.success(); fail( "Should not be able to create constraint on multiple propertyKey keys" ); } catch ( UnsupportedOperationException e ) { assertThat( e.getMessage(), containsString( "can only create one unique constraint" ) ); } }
private void assertDisallow(Table table, TableAction action) throws IOException { try { action.call(table); fail("Should not allow the action"); } catch (DoNotRetryIOException | RetriesExhaustedException e) { // expected assertThat(e.getMessage(), containsString("STANDBY")); } }
@Test public void flowTracing_SupplierOfFormattedMessage() { logger.traceEntry(new Supplier<FormattedMessage>() { @Override public FormattedMessage get() { return new FormattedMessage("int foo={}", 1234567890); } }); assertEquals(1, results.size()); assertThat("Incorrect Entry", results.get(0), startsWith("ENTER[ FLOW ] TRACE Enter")); assertThat("Missing entry data", results.get(0), containsString("(int foo=1234567890)")); assertThat("Bad toString()", results.get(0), not(containsString("FormattedMessage"))); }
@Test public void testThrowsExceptionIfTooManyProxies() { try { WrappingProxyUtil.stripProxy(new SelfWrappingProxy(WrappingProxyUtil.SAFETY_NET_MAX_ITERATIONS)); fail("Expected exception not thrown"); } catch (final IllegalArgumentException e) { assertThat(e.getMessage(), containsString("Are there loops in the object graph?")); } }
@Test public void test() { ClassNode cls = getClassNode(TestCls.class); String code = cls.getCode().toString(); assertThat(code, containsString("public ItemReference(V item, Object id, ReferenceQueue<? super V> queue) {")); assertThat(code, containsString("public V get(Object id) {")); assertThat(code, containsString("WeakReference<V> ref = ")); assertThat(code, containsString("return ref != null ? ref.get() : null;")); } }
@Test public void bogusAllowCredentialsValue() throws Exception { exception.expect(IllegalStateException.class); exception.expectMessage(containsString("@CrossOrigin's allowCredentials")); exception.expectMessage(containsString("current value is [bogus]")); this.handlerMapping.registerHandler(new MethodLevelControllerWithBogusAllowCredentialsValue()); }
@Test public void testFailBadVersion() throws Exception { final Task task = new NoopTask(null, null, 0, 0, null, null, null); final SegmentTransactionalInsertAction action = new SegmentTransactionalInsertAction(ImmutableSet.of(SEGMENT3)); actionTestKit.getTaskLockbox().add(task); actionTestKit.getTaskLockbox().lock(TaskLockType.EXCLUSIVE, task, INTERVAL, 5000); thrown.expect(IllegalStateException.class); thrown.expectMessage(CoreMatchers.containsString("are not covered by locks")); SegmentPublishResult result = action.perform(task, actionTestKit.getTaskActionToolbox()); Assert.assertEquals(new SegmentPublishResult(ImmutableSet.of(SEGMENT3), true), result); } }
/** * Tries to write a journal entry and expects the write to fail due to {@link IOException}. * * @param writer {@link UfsJournalLogWriter} that attempts the write * @param nextSN the sequence number that the entry is expected to have */ private void tryWriteAndExpectToFail(UfsJournalLogWriter writer, long nextSN) throws Exception { try { writer.write(newEntry(nextSN)); Assert.fail("Should not reach here."); } catch (IOException e) { Assert.assertThat(e.getMessage(), containsString(INJECTED_IO_ERROR_MESSAGE)); } }