title: How to test generic abstract class with @Autowired fields?
body: <p>I have generic abstract class AbstractBaseEntityGenericDao which contains @Autowired field. It worked perfectly until I had to write a unit test for it, to not duplicate the same code inside all tests for classes which extends it. And now I'm thinking...Is it possible to write a unit/integration test for such class?</p>
  
  <pre><code>@Repository
  @Transactional
  public abstract class AbstractBaseEntityGenericDao&lt;T extends BaseEntity&gt; {
  
      private Class&lt;T&gt; classInstance;
  
      private SessionFactory sessionFactory;
  
      @Autowired
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      public final void setClassInstance(Class&lt;T&gt; clasInstance) {
          this.classInstance = clasInstance;
      }
  
      public void create(@NonNull T entity) {
          Session session = sessionFactory.getCurrentSession();
          session.save(entity);
      }
  
      public Optional&lt;T&gt; find(long id) {
          Session session = sessionFactory.getCurrentSession();
          return Optional.ofNullable(session.get(classInstance, id));
      }
  
      public void update(@NonNull T entity) {
          Session session = sessionFactory.getCurrentSession();
          session.saveOrUpdate(entity);
      }
  
      public void remove(@NonNull Long id) throws EntityNotFoundException {
          Session session = sessionFactory.getCurrentSession();
          session.remove(session.load(classInstance, id));
      }
  
      public void remove(@NonNull T entity) {
          Session session = sessionFactory.getCurrentSession();
          session.remove(entity);
      }
  }
  </code></pre>