Skip to content

Commit

Permalink
Commit with removed code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
Lena Sotnik authored and Lena Sotnik committed Jan 15, 2024
1 parent 9569522 commit a361c64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@ExtendWith(SpringExtension.class)
class MultipartFileImplTest {
@Test
public void testMultipartFileMethods() throws IOException {
void testMultipartFileMethods() throws IOException {
String name = "file";
String originalFilename = "test.txt";
String contentType = "text/plain";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import greencity.entity.SocialNetworkImage;
import greencity.repository.SocialNetworkImageRepo;
import java.net.URI;
import java.net.URL;
import java.nio.file.Paths;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -20,18 +20,16 @@

@ExtendWith(MockitoExtension.class)
class SocialNetworkImageServiceImplTest {

@Mock
SocialNetworkImageRepo socialNetworkImageRepo;
@Mock
ModelMapper modelMapper;
@InjectMocks
SocialNetworkImageServiceImpl socialNetworkImageService;
private static final String TEST_URL = "http://example.com";

@Test
void getSocialNetworkImageByUrl() throws Exception {
URL checkUrl = new URL("HTTP://");
void getSocialNetworkImageByUrl() {
URI checkUrl = Paths.get("HTTP://").toUri();
SocialNetworkImageVO socialNetworkImageVO = new SocialNetworkImageVO();
socialNetworkImageVO.setId(1L);
socialNetworkImageVO.setHostPath(checkUrl.getHost());
Expand All @@ -50,21 +48,21 @@ void getSocialNetworkImageByUrl() throws Exception {

@Test
void getSocialNetworkImageByUrlBadRequest() throws Exception {
URI checkUrl = new URI(TEST_URL);

URI checkUrl = new URI("https://example.com");
SocialNetworkImageVO socialNetworkImageVO = new SocialNetworkImageVO();
socialNetworkImageVO.setId(1L);
socialNetworkImageVO.setHostPath(checkUrl.getHost());
socialNetworkImageVO.setImagePath(checkUrl.getPath());

when(socialNetworkImageRepo.findByHostPath(checkUrl.getHost())).thenReturn(null);

assertThrows(RuntimeException.class, () -> socialNetworkImageService.getSocialNetworkImageByUrl(TEST_URL));
assertThrows(RuntimeException.class,
() -> socialNetworkImageService.getSocialNetworkImageByUrl(checkUrl.toString()));
}

@Test
void findByHostPath() throws Exception {
URI checkUrl = new URI("HTTP://example.com/");
void findByHostPath() {
URI checkUrl = Paths.get("HTTP://example.com/").toUri();
SocialNetworkImageVO socialNetworkImageVO = new SocialNetworkImageVO();
socialNetworkImageVO.setId(1L);
socialNetworkImageVO.setHostPath(checkUrl.getHost());
Expand Down

0 comments on commit a361c64

Please sign in to comment.