0
votes

The methods : findAll(),save(O o), findOne(long id) of interface Repository is not found in my spring jpa integration test.

package source;

import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;

import category.IntegrationTest;
import domain.BankAccount;
import presentation.MessageContext;
import repository.BankAccountRepository;

@RunWith(SpringRunner.class)
@Category(IntegrationTest.class)
@DataJpaTest
public class BankAccountTest {


     @Autowired
        private BankAccountRepository repository;
     @Test
        public void should_find_no_customers_if_repository_is_empty() {
            Iterable<BankAccount> accounts = repository.findAll();

            assertNull(accounts);
        }

    @Test
    public void shuldCreateBankAccount() {
             BankAccount accounts = new  BankAccount(100);
             repository.save(accounts);
            BankAccount accountr =  repository.findOne(1l);
            assertNotNull(accountr);
          }
    }

The repository interface looks like this

package repository;
import org.springframework.data.repository.Repository;
import domain.BankAccount;
public interface BankAccountRepository extends Repository<BankAccount, Long> {}

I have also implemeneted a configuration file

package repository;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@Configuration
@EnableJpaRepositories

public class PersistentContext {}

the classes is placed like this Component structure

What must i to compile the code without errors?

1

1 Answers

0
votes

interface Repository is empty interface ,it's common interface for spring data repositories . There is no any method , see Repository API .

If you need method findAll(),save(O o), findOne(long id) you need use CrudRepository - it's sub interface for interface Repository , or you can use JpaRepository - it's extension of CrudRepository.