### Question:
JsonWorkspaceService implements WorkspaceService { @Override @SuppressWarnings("unchecked") public Map<String, Map<String, String>> loadWorkspace(File workspace) { requireNotNullArg(workspace, "Workspace file cannot be null"); Map<String, Map<String, String>> data = Collections.emptyMap(); try (FileInputStream stream = new FileInputStream(workspace)) { data = (Map) JSON.std.mapFrom(stream); } catch (Exception e) { throw new RuntimeException(e); } return data; }  @Override void saveWorkspace(Map<String, Map<String, String>> data, File destination); @Override @SuppressWarnings("unchecked") Map<String, Map<String, String>> loadWorkspace(File workspace);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void loadNull() { victim.loadWorkspace(null); }
@Test public void loadWorkspace() throws IOException { File file = folder.newFile(); FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("/workspace.json"), file); Map<String, Map<String, String>> result = victim.loadWorkspace(file); assertFalse(result.isEmpty()); assertNotNull(result.get("split.bybookmarks")); assertFalse(result.get("split.bybookmarks").isEmpty()); }
@Test(expected = RuntimeException.class) public void loadBrokenWorkspace() throws IOException { File file = folder.newFile(); FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("/broken_workspace.json"), file); victim.loadWorkspace(file); }
@Test(expected = RuntimeException.class) public void cannotAccessWorkspace() throws IOException { File file = folder.newFile(); FileUtils.copyInputStreamToFile(getClass().getResourceAsStream("/workspace.json"), file); if (!file.setReadable(false)) { throw new RuntimeException("OS does not implement read pemissions"); } victim.loadWorkspace(file); }
@Test(expected = RuntimeException.class) public void loadNotExistent() { File file = new File("I dont exist"); victim.loadWorkspace(file); }