将AppendixFileNotFoundException改为了IOException,增加了一些测试
This commit is contained in:
parent
7e43a10dc3
commit
615c5a8f42
@ -137,7 +137,7 @@ public class FileSystem {
|
||||
* 根据id获取一个文件的条目,其中包含文件信息
|
||||
* @param id 要寻找条目的id
|
||||
*/
|
||||
public AppendixFile getFileData(int id)
|
||||
public AppendixFile getFileData(int id)throws AppendixFileNotFoundException
|
||||
{
|
||||
Optional<AppendixFile> optionalAppendixFile = appendixFileService.findById(id);
|
||||
if(!optionalAppendixFile.isPresent())
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user