@Test
  public void load_ShouldGetAllFiles() throws InvalidConfigurationException, PersistenceException {
    Map<String, String> metaData = Collections.emptyMap();

    List<ConfigItem<Map<String, String>>> items = persistenceService.load(metaData);

    assertThat(items.size(), is(3));
  }
  @Test
  public void removingConfiguration_ShouldDeleteFile() throws PersistenceException {
    File configFileThatShouldBeDeleted = new File(temporaryFolder.getRoot(), "context3.context");

    persistenceService.remove(getMetaDataWithContextId("context3"));

    assertThat(configFileThatShouldBeDeleted.exists(), is(false));
  }
  @Before
  public void setUp() throws IOException {
    temporaryFolder.newFile("context1.context");
    temporaryFolder.newFile("context2.context");
    temporaryFolder.newFile("context3.context");
    temporaryFolder.newFile("unknown.file");

    persistenceService = new ContextFilePersistenceService();
    persistenceService.setStorageFolderPath(temporaryFolder.getRoot().getAbsolutePath());
  }
  @Test
  public void persistingContext_shouldCreateNewFile()
      throws InvalidConfigurationException, PersistenceException {
    File configFileThatShouldBeCreated = new File(temporaryFolder.getRoot(), "contextFoo.context");
    Integer filesBefore = countFilesInTempFolder();

    persistenceService.persist(getEmptyContextConfigurationWithId("contextFoo"));
    Integer filesAfter = countFilesInTempFolder();

    assertThat(filesAfter, is(filesBefore + 1));
    assertThat(configFileThatShouldBeCreated.exists(), is(true));
  }
  @Test
  public void filteredLoad_shouldReturnConfigurationWithCorrespindingMetaData()
      throws InvalidConfigurationException, PersistenceException {
    Map<String, String> metaData = new HashMap<String, String>();
    metaData.put(ContextId.META_KEY_ID, "context2");

    List<ConfigItem<Map<String, String>>> items = persistenceService.load(metaData);

    assertThat(items.size(), is(1));
    ConfigItem<?> loadedConfiguration = items.get(0);
    assertThat(loadedConfiguration.getMetaData().get(ContextId.META_KEY_ID), is("context2"));
  }
 @Test(expected = IllegalArgumentException.class)
 public void persistingUnknownItemType_shouldThrowException()
     throws InvalidConfigurationException, PersistenceException {
   persistenceService.persist(new UnknownConfigItem());
 }
 @Test
 public void contextFilePersistenceService_shouldNotSupportUnknownConfigItemType()
     throws InvalidConfigurationException, PersistenceException, IOException {
   assertThat(persistenceService.supports(UnknownConfigItem.class), is(false));
 }
 @Test
 public void contextFilePersistenceService_shouldSupportContext()
     throws InvalidConfigurationException, PersistenceException, IOException {
   assertThat(persistenceService.supports(ContextConfiguration.class), is(true));
 }