@Test
 public void loadAndRead() throws IOException {
   when(repository.findOne(new QueryImpl().eq("Name", "template1"))).thenReturn(template1);
   Object source = repositoryTemplateLoader.findTemplateSource("template1");
   assertNotNull(source);
   Reader reader = repositoryTemplateLoader.getReader(source, null);
   assertTrue(IOUtils.contentEquals(reader, new StringReader(template1.getValue())));
 }
 @Test
 public void newSourceReturnedWhenContentChanges() throws IOException {
   when(repository.findOne(new QueryImpl().eq("Name", "template1")))
       .thenReturn(template1, template1Modified);
   Object source = repositoryTemplateLoader.findTemplateSource("template1");
   assertTrue(
       IOUtils.contentEquals(
           repositoryTemplateLoader.getReader(source, null),
           new StringReader(template1.getValue())));
   Object modifiedSource = repositoryTemplateLoader.findTemplateSource("template1");
   assertNotEquals(source, modifiedSource);
   assertTrue(
       IOUtils.contentEquals(
           repositoryTemplateLoader.getReader(modifiedSource, null),
           new StringReader(template1Modified.getValue())));
 }
  @Test
  public void sourceBelongsToContentAndCanBeReadMultipleTimes() throws IOException {
    when(repository.findOne(new QueryImpl().eq("Name", "template1"))).thenReturn(template1);
    when(repository.findOne(new QueryImpl().eq("Name", "template2"))).thenReturn(template2);

    Object source1 = repositoryTemplateLoader.findTemplateSource("template1");
    Object source2 = repositoryTemplateLoader.findTemplateSource("template2");

    assertTrue(
        IOUtils.contentEquals(
            repositoryTemplateLoader.getReader(source2, null),
            new StringReader(template2.getValue())));

    assertTrue(
        IOUtils.contentEquals(
            repositoryTemplateLoader.getReader(source1, null),
            new StringReader(template1.getValue())));

    assertTrue(
        IOUtils.contentEquals(
            repositoryTemplateLoader.getReader(source1, null),
            new StringReader(template1.getValue())));

    assertTrue(
        IOUtils.contentEquals(
            repositoryTemplateLoader.getReader(source1, null),
            new StringReader(template1.getValue())));

    assertTrue(
        IOUtils.contentEquals(
            repositoryTemplateLoader.getReader(source2, null),
            new StringReader(template2.getValue())));
  }
 @Test
 public void lastModifiedEqualsMinusOne() throws IOException {
   when(repository.findOne(new QueryImpl().eq("Name", "template1"))).thenReturn(template1);
   Object source = repositoryTemplateLoader.findTemplateSource("template1");
   assertTrue(repositoryTemplateLoader.getLastModified(source) == -1);
 }