@Test(expected = IOException.class)
  public void handlesCheckedExceptionsCorrectly() throws Exception {

    SampleRepository repository =
        factory.getRepository(SampleRepository.class, new SampleCustomRepositoryImpl());
    repository.throwingCheckedException();
  }
  @Test(expected = IllegalArgumentException.class)
  public void handlesRuntimeExceptionsCorrectly() {

    SampleRepository repository =
        factory.getRepository(SampleRepository.class, new SampleCustomRepositoryImpl());
    repository.throwingRuntimeException();
  }
  @Test
  public void allowsCallingOfObjectMethods() {

    SimpleSampleRepository repository = factory.getRepository(SimpleSampleRepository.class);

    repository.hashCode();
    repository.toString();
    repository.equals(repository);
  }
  @Test(expected = UnsupportedOperationException.class)
  public void createsProxyWithCustomBaseClass() {

    JpaRepositoryFactory factory = new CustomGenericJpaRepositoryFactory(entityManager);
    UserCustomExtendedRepository repository =
        factory.getRepository(UserCustomExtendedRepository.class);

    repository.customMethod(1);
  }
  /**
   * Asserts that the factory recognized configured repository classes that contain custom method
   * but no custom implementation could be found. Furthremore the exception has to contain the name
   * of the repository interface as for a large repository configuration it's hard to find out where
   * this error occured.
   *
   * @throws Exception
   */
  @Test
  public void capturesMissingCustomImplementationAndProvidesInterfacename() throws Exception {

    try {
      factory.getRepository(SampleRepository.class);
    } catch (IllegalArgumentException e) {
      assertTrue(e.getMessage().contains(SampleRepository.class.getName()));
    }
  }
  @Test
  public void usesQueryDslRepositoryIfInterfaceImplementsExecutor() {

    when(metadata.getJavaType()).thenReturn(User.class);
    assertEquals(
        QueryDslJpaRepository.class,
        factory.getRepositoryBaseClass(
            new DefaultRepositoryMetadata(QueryDslSampleRepository.class)));

    try {
      QueryDslSampleRepository repository = factory.getRepository(QueryDslSampleRepository.class);
      assertEquals(QueryDslJpaRepository.class, ((Advised) repository).getTargetClass());
    } catch (IllegalArgumentException e) {
      assertThat(
          e.getStackTrace()[0].getClassName(),
          is("org.springframework.data.querydsl.SimpleEntityPathResolver"));
    }
  }
  /**
   * Assert that the instance created for the standard configuration is a valid {@code
   * UserRepository}.
   *
   * @throws Exception
   */
  @Test
  public void setsUpBasicInstanceCorrectly() throws Exception {

    assertNotNull(factory.getRepository(SimpleSampleRepository.class));
  }