Pattern selector

Most relevant patterns first. Most helpful ones displayed. Click here to show all.

  1. JUnit and Hamcrest with "assertThat" comparison failed
    JUnit
    4
    24
    10

Your stack trace compared to the selected pattern

Jump to solutionsExpand frames
java.lang.AssertionError: @Scheduled method never called Expected: a value greater than <0> got: <0>
    at org.junit.Assert.assertThat(Assert.java:780)
    at org.springframework.scheduling.annotation.ScheduledAndTransactionalAnnotationIntegrationTests.succeedsWhenSubclassProxyAndScheduledMethodNotPresentOnInterface(ScheduledAndTransactionalAnnotationIntegrationTests.java:77)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
32 frames hidden

Solution

JaviRpo2 months ago

AssertionError is thrown when using JUnit's internal assertions don't match by a condition specified by matcher in the Assert.assertThat method.

This JUnit method can be used to compare a value with a matcher expression.

Here is an example:

import static org.junit.Assert.assertThat;
import static org.hamcrest.CoreMatchers.*;

public class ObjectComparisonTest { 

   @Test 
   public void shouldAssertStrings() { 
      assertThat("myValue", allOf(startsWith("my"), containsString("Val"))); // passes

      assertThat("myValue", endsWith("Val")); // fails
   } 

   @Test 
   public void shouldAssertNumbers() { 
      assertThat("Zero is one", 0, is(not(1))) // passes

      assertThat("Help! Integers don't work", 0, is(1));   // fails:
      // failure message:
      // Help! Integers don't work
      // expected: is <1>
      // got value: <0>
   } 

   @Test 
   public void shouldAssertObjects() {
      Person p = new Person();
      assertThat(p, instanceOf(Person.class));  // The object instance's class if the same.
   } 
}

class Person { ... }

Mind the static import.

  • The assertThat is part of the JUnit API.
  • The is, not, startsWith, containsString, endsWith, allOf and instanceOf are part of the Hamcrest API and it has more and more util methods.

If you're using the assertThat method, you need to check the value expected and the matcher used to compare it.

External results for this pattern (10)

  1. kazuki43zoovia GitHub4 months ago
  2. btkatoutkmvia GitHub4 months ago
    Expected: is "[org.terasoluna.gfw.common.codelist.i18n.SimpleI18nCodeList@3704122f, org.terasoluna.gfw.common.codelist.NumberRangeCodeList@7577b641, org.terasoluna.gfw.common.codelist.SimpleMapCodeList@2fa7ae9]" got: "[org.terasoluna.gfw.common.codelist.SimpleMapCodeList@2fa7ae9, org.terasoluna.gfw.common.codelist.NumberRangeCodeList@7577b641, org.terasoluna.gfw.common.codelist.i18n.SimpleI18nCodeList@3704122f]"
    Show stack trace
  3. Stevo Slavićvia Spring JIRA4 months ago
    @Scheduled method never called Expected: a value greater than <0> got: <0>
    Show stack trace
  4. Maciej Zasada [Atlassian]via Atlassian JIRA4 months ago
    Should find a single content for CQL input: 'content.property[aggregates].content.editTime >= 2001-01-01' Expected: an iterable with size <1> got: <RestList{results=[], pageRequest=SimplePageRequest{start=0, limit=25}, hasMore=false}>
    Show stack trace
  5. Unknown authorvia yahoo.com4 months ago
    Expected: a CDR record with call ID: 12345678900 got: <org.cafesip.sipexchange.ejbs.cdr.value.CdrRecord@1712b3a>
    Show stack trace
  6. David Pilatovia Apache's JIRA Issue Tracker4 months ago
    Expected: null got: "sun.awt.X11FontManager"
    Show stack trace
  7. Unknown authorvia eclipse.org4 months ago
    Expected: is "Not Found" got: "Change is not abandoned or patchset is not latest"
    Show stack trace
  8. aslakhellesoyvia GitHub4 months ago
    Expected: a string containing "index.html" got: ""
    Show stack trace
  9. Neiko2002via GitHub4 months ago
    Expected: is <805568512> got: <939786240>
    Show stack trace
  10. Unknown authorvia ne.jp4 months ago