@Test
  public void testFindAll() {

    List<TestEntity> values =
        Arrays.asList(1, 2)
            .stream()
            .map(
                v -> {
                  TestEntity t = new TestEntity();
                  t.setStringProperty(String.format("Hello %s time(s)", v));
                  return t;
                })
            .collect(Collectors.toList());
    repository.save(values);

    List<TestEntity> actual = (List<TestEntity>) repository.findAll();

    assertNotNull("Checking that the result is not null.", actual);
    assertEquals(2, actual.size());

    Map<String, TestEntity> expected =
        values.stream().collect(toMap(TestEntity::getId, Function.identity()));
    actual.forEach(
        testEntity ->
            assertEquals(
                expected.get(testEntity.getId()).getStringProperty(),
                testEntity.getStringProperty()));
  }
  @Test
  public void testFindOne() {

    List<TestEntity> values =
        Arrays.asList(1, 2)
            .stream()
            .map(
                v -> {
                  TestEntity t = new TestEntity();
                  t.setStringProperty(String.format("Hello %s time(s)", v));

                  return t;
                })
            .collect(Collectors.toList());
    repository.save(values);

    TestEntity actual = repository.findOne(values.get(1).getId());

    assertNotNull("Checking that the result is not null.", actual);
    assertEquals(
        "Checking that the list is the expected size.", values.get(1).getId(), actual.getId());
    assertEquals(
        "Checking that the list is the expected size.",
        values.get(1).getStringProperty(),
        actual.getStringProperty());
  }
  @Test
  public void testDeleteEntity() {

    TestEntity t = new TestEntity();
    t.setStringProperty(String.format("Hello World!"));

    repository.save(t);
    repository.delete(Arrays.asList(t));

    TestEntity actual = repository.findById(t.getId());

    assertNull("Checking that the result is null.", actual);
  }
  @Test
  public void testDeleteAllEntities() {

    TestEntity t1 = new TestEntity();
    t1.setStringProperty(String.format("1"));

    TestEntity t2 = new TestEntity();
    t2.setStringProperty(String.format("2"));

    repository.save(Arrays.asList(t1, t2));
    repository.deleteAll();

    assertNull("Checking that the result is null.", repository.findById(t1.getId()));
    assertNull("Checking that the result is null.", repository.findById(t2.getId()));
  }
  @Test
  public void testFindOneReturnsNullWhenIdNotFound() {

    TestEntity actual = repository.findOne("non-existent ID");

    assertThat(actual, is(nullValue()));
  }
  @Test
  public void testCount() {

    List<TestEntity> values =
        Arrays.asList(1, 2)
            .stream()
            .map(
                v -> {
                  TestEntity t = new TestEntity();
                  t.setStringProperty(String.format("Hello %s time(s)", v));
                  return t;
                })
            .collect(Collectors.toList());
    repository.save(values);

    assertThat(repository.count(), equalTo(2L));
  }
  @Test
  public void testExists() {

    List<TestEntity> values =
        Arrays.asList(1, 2)
            .stream()
            .map(
                v -> {
                  TestEntity t = new TestEntity();
                  t.setStringProperty(String.format("Hello %s time(s)", v));
                  return t;
                })
            .collect(Collectors.toList());
    repository.save(values);

    assertTrue(repository.exists(values.get(1).getId()));
    assertFalse(repository.exists("3"));
  }
  @Test
  public void testSave_PreSaveListenerFired() {

    TestEntity testEntity = new TestEntity();
    testEntity.setStringProperty("Hello World!");

    repository.save(testEntity);

    assertEquals("Checking that the listener was fired.", 1, preSaveCount.get());
  }
  @Test
  public void testSave() {

    TestEntity testEntity = new TestEntity();
    testEntity.setStringProperty("Hello World!");

    TestEntity result = repository.save(testEntity);

    assertNotNull("Checking that the result is not null.", result);
  }
  /**
   * Because of an issue with wiremock, specifically related to PUT operations following GET
   * operations, I'm adding this before block. If the save op fails, it should only fail the first
   * time.
   */
  @Before
  public void before() {

    TestEntity e = new TestEntity();

    try {

      repository.save(e);

    } catch (Exception e1) {
    }

    try {

      repository.delete(e);

    } catch (Exception e1) {
    }

    preSaveCount.set(0);
    postSaveCount.set(0);
  }
  @Test
  public void testSaveList() {

    List<TestEntity> values =
        Arrays.asList(1, 2)
            .stream()
            .map(
                v -> {
                  TestEntity t = new TestEntity();
                  t.setStringProperty(String.format("Hello %s time(s)", v));

                  return t;
                })
            .collect(Collectors.toList());

    List<TestEntity> result = (List<TestEntity>) repository.save(values);

    assertNotNull("Checking that the result is not null.", result);
    assertEquals("Checking that the list is the expected size.", 2, result.size());
  }