Hallo Leute, an sich komme ich mit den Tests gut voran, bis zu diesem Punkt wo es mir kein richtiger Fehler angezeigt wird:
Spring-Boot meldet:
Die Methoden von zwei Delegierungsklassen (FileSystem, Thumbnail) funktionieren;
Leider bekomme ich keine vernünftige Rückmeldung und weiß daher nicht woran es scheitert. Meine Vermutung wäre dass es hier um Mock-Objekte handelt. Das Logging funktioniert an anderen Stellen.
Java:
package com.tutego.date4u.core;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Base64;
import java.util.Optional;
import javax.imageio.ImageIO;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import com.tutego.date4u.components.AwtBicubicThumbnail;
import com.tutego.date4u.images.FileSystem;
import com.tutego.date4u.images.PhotoService;
@SpringBootTest(properties = {"spring.shell.interactive.enabled=false"})
@ExtendWith(MockitoExtension.class)
public class CopleTest {
Logger log = LoggerFactory.getLogger(getClass());
@Autowired PhotoService photoService;
@SpyBean AwtBicubicThumbnail thumbnail;
@MockBean FileSystem fileSystem;
@Test
public void action(){
Optional<byte[]> byteImage = photoService.download("tree");
log.info("Der Download war erfolgreich");
byte [] bytes = fileSystem.load("tree.jpg");
log.info("Das Bild wurde erfolgreich geladen");
//byte[] bytes = Files.readAllBytes(Paths.get("C:\\Users\\iRahi\\fs\\" + "tree" + ".jpg"));
photoService.upload(bytes);
log.info("Das Bild war erfolgreich gespeichert");
}
}
Spring-Boot meldet:
Code:
15:36:49.809 [main] INFO org.springframework.test.context.support.AnnotationConfigContextLoaderUtils -- Could not detect default configuration classes for test class [com.tutego.date4u.core.CopleTest]: CopleTest does not declare any static, non-private, non-final, nested classes annotated with @Configuration.
15:36:49.961 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper -- Found @SpringBootConfiguration com.tutego.date4u.Date4uAppApplication for test class com.tutego.date4u.core.CopleTest
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v3.2.0)
2023-12-07T15:36:50.597+01:00 INFO 9436 --- [ main] com.tutego.date4u.core.CopleTest : Starting CopleTest using Java 17.0.7 with PID 9436 (started by iRahi in C:\Users\iRahi\eclipse-workspace\Date4uApp)
2023-12-07T15:36:50.602+01:00 INFO 9436 --- [ main] com.tutego.date4u.core.CopleTest : No active profile set, falling back to 1 default profile: "default"
2023-12-07T15:36:52.982+01:00 WARN 9436 --- [ main] org.jline : Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
Die Methoden von zwei Delegierungsklassen (FileSystem, Thumbnail) funktionieren;
Code:
PhotoService:
public Optional<byte[]> download(String name){
try { return Optional.of(fileSystem.load(name + ".jpg"));}
catch(UncheckedIOException e) {return Optional.empty();}
}
public String upload(byte[] imageBytes) {
String imageName = UUID.randomUUID().toString();
fileSystem.store(imageName + ".jpg", imageBytes);
byte[] thumbnailBytes = thumbnail.thumbnail(imageBytes);
fileSystem.store(imageName + "-thumb.jpg", thumbnailBytes);
return imageName;
}
FileSystem:
public byte[] load(String filename) {
try { return Files.readAllBytes(Paths.get(System.getProperty("user.home")).resolve("fs\\" + filename + ".jpg" )); }
catch(IOException e) {throw new UncheckedIOException(e);}
}
public void store(String filename, byte[] bytes) {
try {Files.write(Paths.get(System.getProperty("user.home")).resolve("fs\\" + filename + ".jpg" ), bytes);}
catch(IOException e) {throw new UncheckedIOException(e);}
}
Leider bekomme ich keine vernünftige Rückmeldung und weiß daher nicht woran es scheitert. Meine Vermutung wäre dass es hier um Mock-Objekte handelt. Das Logging funktioniert an anderen Stellen.