So I have a simple entity:
//imports .... @Entity @Table(name="ratings") public class Rating { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; public Long getId() { return id; } public void setId(Long id) { this.id = id; } .... } Test:
import static org.hamcrest.Matchers.*; .... @Test public void shouldCreateARating() throws Exception { Rating expected = createdRating; assertThat(existingRating.getId(), is(1L)); } ... But when I try to compile, I get this compilation error:
[ERROR] /c:/limits/src/test/java/hello/RatingsControllerTest.java:[170,33] c:\limits\src\test\java\hello\RatingsControllerTest.java:170: cannot find symbol symbol : method assertThat(java.lang.Long,org.hamcrest.Matcher<java.lang.Long>) location: class hello.RatingsControllerTest I checked and is(T value) exists, and assertThat(T actual, org.hamcrest.Matcher<T> matcher) exist and are imported... so what is going on here? How can I test that a Long has the value I expect if combining the is and assertThat for Long generates a compilation error?
An explanation of why I am testing the get id --- it is a nested object that I save in setup() and its getId() value comes up as null in the test, even though I know that I save it (which hibernate generates an id for).
Making me feel like an idiot.