将AppendixFileNotFoundException改为了IOException,增加了一些测试

This commit is contained in:
ddaa2000 2020-04-12 18:07:45 +08:00
parent 7e43a10dc3
commit 615c5a8f42
3 changed files with 43 additions and 3 deletions

View File

@ -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())

View File

@ -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;

View File

@ -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);