Announcement Announcement Module
Collapse
No announcement yet.
spring data crudrepo and junit test issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • spring data crudrepo and junit test issue

    I have a Junit test class that contains two methods-- one that saves into the database using an interface that extends CrudRepo and the other method that retrieves data from the database. When I run my tests, the save works but the retrieve doesn't. Any ideas why? See below Test class. The "MyTestRepo" extends CrudRepository so it includes the default findOne():

    Code:
    @Autowired 
    private MyTestRepo repo;
    
    @Test
    public void saveIntoTestRepo(){
        SomeObject so = new SomeObject();
        SomeObject result = repo.save(so);
        assertThat(result.getId(), is(notNullValue()));  //this passes, the id = 1
    }
    
    @Test
    public void retrieveSO() {
        repo.count();  // this is correct, returns 1
        SomeObject result = repo.findOne(1L);  //this should return the hydrated SomeObject instance with id = 1
        assertThat(result, is(notNullValue()));  // Fails here since the result is null...
    }
Working...
X