Merge branch 'TestsBesoin1' into 'main'
Tests besoin1 See merge request pdl-l3/teams/2023/v1/v1d!13
This commit is contained in:
commit
56e6305d5a
11 files changed
+52
-12
No files matched your search
@@ -16,21 +16,23 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public class ImageDao implements Dao<Image> {
|
||||
|
||||
private final static String[] ACCEPTED_EXTENSION = { "jpg", "png", "jpeg" };
|
||||
|
||||
private final Map<Long, Image> images = new HashMap<>();
|
||||
|
||||
public ImageDao() {
|
||||
try {
|
||||
final var folderPath = new ClassPathResource("images");
|
||||
if (!folderPath.exists())
|
||||
throw new ImageResourceMissingException("folder images doesn't not exsit");
|
||||
final var folder = folderPath.getFile();
|
||||
getAllImages(folder);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public ImageDao() throws IOException {
|
||||
this("images");
|
||||
}
|
||||
|
||||
public void getAllImages(final File folder) {
|
||||
public ImageDao(final String folderPathStr) throws IOException {
|
||||
final var folderPath = new ClassPathResource(folderPathStr);
|
||||
if (!folderPath.exists())
|
||||
throw new ImageResourceMissingException("folder images doesn't not exist");
|
||||
final var folder = folderPath.getFile();
|
||||
getAllImages(folder);
|
||||
}
|
||||
|
||||
private void getAllImages(final File folder) {
|
||||
for (final File file : folder.listFiles()) {
|
||||
if (file.isDirectory()) {
|
||||
getAllImages(file);
|
||||
@@ -41,7 +43,14 @@ public class ImageDao implements Dao<Image> {
|
||||
if (i > 0) {
|
||||
extension = file.getName().substring(i + 1);
|
||||
}
|
||||
if (!extension.equals("jpg") && !extension.equals("png")) {
|
||||
boolean accepted = false;
|
||||
for (final String ext : ACCEPTED_EXTENSION) {
|
||||
if (ext.equals(extension)) {
|
||||
accepted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!accepted) {
|
||||
continue;
|
||||
}
|
||||
byte[] fileContent;
|
||||
|
||||
File renamed without changes.
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 203 KiB |
@@ -0,0 +1 @@
|
||||
LION
|
||||
@@ -0,0 +1 @@
|
||||
GUITARE
|
||||
@@ -0,0 +1 @@
|
||||
# BOO
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 38 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 314 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
@@ -0,0 +1,28 @@
|
||||
package pdl.backend;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ImageDaoTests {
|
||||
|
||||
@Test
|
||||
@DisplayName("ImageDao should throw an exception when the image folder is missing")
|
||||
public void exceptionImageFolderNotFound() throws Exception {
|
||||
assertThrows(IOException.class, () -> {
|
||||
new ImageDao("testing");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("ImageDao should have all images of the folder / subfolders and should ignore non (JPG/PNG) files")
|
||||
public void initImageDao() throws Exception {
|
||||
ImageDao imageDao = new ImageDao("imagesTest");
|
||||
var listImages = imageDao.retrieveAll();
|
||||
assert (listImages.size() == 5);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user