diff --git a/src/main/java/com/codesdream/ase/component/activity/FileSystem.java b/src/main/java/com/codesdream/ase/component/activity/FileSystem.java index 659437d..f0fab48 100644 --- a/src/main/java/com/codesdream/ase/component/activity/FileSystem.java +++ b/src/main/java/com/codesdream/ase/component/activity/FileSystem.java @@ -137,7 +137,7 @@ public class FileSystem { * 根据id获取一个文件的条目,其中包含文件信息 * @param id 要寻找条目的id */ - public AppendixFile getFileData(int id) + public AppendixFile getFileData(int id)throws AppendixFileNotFoundException { Optional optionalAppendixFile = appendixFileService.findById(id); if(!optionalAppendixFile.isPresent()) diff --git a/src/main/java/com/codesdream/ase/exception/notfound/AppendixFileNotFoundException.java b/src/main/java/com/codesdream/ase/exception/notfound/AppendixFileNotFoundException.java index 03f4784..0025243 100644 --- a/src/main/java/com/codesdream/ase/exception/notfound/AppendixFileNotFoundException.java +++ b/src/main/java/com/codesdream/ase/exception/notfound/AppendixFileNotFoundException.java @@ -2,7 +2,9 @@ package com.codesdream.ase.exception.notfound; import com.codesdream.ase.model.activity.AppendixFile; -public class AppendixFileNotFoundException extends NotFoundException { +import java.io.IOException; + +public class AppendixFileNotFoundException extends IOException { public int id; public int type; public static final int ID_NOT_FOUND = 1, FILE_NOT_fOUND = 2, STREAM_FAILURE = 3; diff --git a/src/test/java/com/codesdream/ase/test/FileSystemTest.java b/src/test/java/com/codesdream/ase/test/FileSystemTest.java index c80f8d9..01e66d6 100644 --- a/src/test/java/com/codesdream/ase/test/FileSystemTest.java +++ b/src/test/java/com/codesdream/ase/test/FileSystemTest.java @@ -1,6 +1,7 @@ package com.codesdream.ase.test; import com.codesdream.ase.component.activity.FileSystem; +import com.codesdream.ase.exception.notfound.AppendixFileNotFoundException; import com.codesdream.ase.model.activity.AppendixFile; import com.codesdream.ase.repository.activity.AppendixFileRespository; import com.codesdream.ase.service.AppendixFileService; @@ -47,6 +48,38 @@ public class FileSystemTest { } } + @Test + public void wrongIDTest() + { + int id = 1; + try { + InputStream inputStream = fileSystem.getFile(id); + } catch (AppendixFileNotFoundException e) { + System.out.println(e.getLocalizedMessage()); + } + } + + @Test + public void fileNotExistErrorTest() + { + int id = 268; + try { + InputStream inputStream = fileSystem.getFile(id); + } catch (AppendixFileNotFoundException e) { + System.out.println(e.getLocalizedMessage()); + } + } + + @Test + public void refreshDataBaseTest() + { + fileSystem.databaseRefresh(); + } + @Test + public void refreshDiskTest() + { + fileSystem.diskRefresh(); + } @Test public void createFile() { @@ -63,7 +96,12 @@ public class FileSystemTest { } - InputStream inputStream = fileSystem.getFile(id1); + InputStream inputStream = null; + try { + inputStream = fileSystem.getFile(id1); + } catch (AppendixFileNotFoundException e) { + e.printStackTrace(); + } Scanner scanner = new Scanner(inputStream, "UTF-8"); String text = scanner.useDelimiter("\\A").next(); System.out.println(text);