Skip to content

Commit

Permalink
MARP-1058 Handle Sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
tvtphuc-axonivy committed Sep 13, 2024
1 parent e87836b commit 965f334
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ public String updateImagesWithDownloadUrl(Product product, List<GHContent> conte

allContentOfImages.forEach(content -> {
Image image = imageService.mappingImageFromGHContent(product, content);
System.out.println(content.getName());
imageUrls.put(content.getName(), "imageId-".concat(image.getId()));
});

for (String key : imageUrls.keySet()) {
String imageUrlPattern = String.format(README_IMAGE_FORMAT, Pattern.quote(key));
for (Map.Entry<String, String> entry : imageUrls.entrySet()) {
String imageUrlPattern = String.format(README_IMAGE_FORMAT, Pattern.quote(entry.getKey()));
readmeContents = readmeContents.replaceAll(imageUrlPattern,
String.format(IMAGE_DOWNLOAD_URL_FORMAT, imageUrls.get(key)));
String.format(IMAGE_DOWNLOAD_URL_FORMAT, entry.getValue()));
}

return readmeContents;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
import com.axonivy.market.entity.ProductModuleContent;

public class ImageUtils {

public ImageUtils() {
}

public static ProductModuleContent mappingImageForProductModuleContent(ProductModuleContent productModuleContent) {
if (ObjectUtils.isEmpty(productModuleContent)) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ private ProductJsonContent mockProductJsonContent() {
}

@Test
void test_getImageFromId() throws IOException {
void test_getImageFromId() {
byte[] mockImageData = "image data".getBytes();
when(productService.readImage("66e2b14868f2f95b2f95549a")).thenReturn(mockImageData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,14 @@ void testMappingByGHContent() throws IOException {
}

@Test
void testMappingLogo() throws IOException {
void testMappingLogo() {
Product product = new Product();
GHContent content = mock(GHContent.class);
when(content.getName()).thenReturn(CommonConstants.LOGO_FILE);
var result = ProductFactory.mappingByGHContent(product, content);
assertNotEquals(null, result);

when(content.getName()).thenReturn(CommonConstants.LOGO_FILE);
// when(content.getDownloadUrl()).thenReturn(DUMMY_LOGO_URL);
result = ProductFactory.mappingByGHContent(product, content);
assertNotEquals(null, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ void testGetReadmeAndProductContentFromTag_ImageFromFolder() throws IOException
GHContent mockImageFile = mock(GHContent.class);
when(mockImageFile.getName()).thenReturn(ReadmeConstants.IMAGES, IMAGE_NAME);
when(mockImageFile.isDirectory()).thenReturn(true);
// when(mockImageFile.getDownloadUrl()).thenReturn(IMAGE_DOWNLOAD_URL);
Mockito.when(imageService.mappingImageFromGHContent(any(),any())).thenReturn(mockImage());
PagedIterable<GHContent> pagedIterable = Mockito.mock(String.valueOf(GHContent.class));
when(mockImageFile.listDirectoryContent()).thenReturn(pagedIterable);
Expand Down Expand Up @@ -417,11 +416,10 @@ private GHContent createMockProductFolderWithProductJson() throws IOException {
return mockContent;
}

private static GHContent createMockProductJson() throws IOException {
private static GHContent createMockProductJson() {
GHContent mockProductJson = mock(GHContent.class);
when(mockProductJson.isFile()).thenReturn(true);
when(mockProductJson.getName()).thenReturn(ProductJsonConstants.PRODUCT_JSON_FILE, IMAGE_NAME);
// when(mockProductJson.getDownloadUrl()).thenReturn(IMAGE_DOWNLOAD_URL);
return mockProductJson;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.axonivy.market.repository.ImageRepository;

@ExtendWith(MockitoExtension.class)
public class ImageServiceImplTest {
class ImageServiceImplTest {
@InjectMocks
private ImageServiceImpl imageService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.axonivy.market.entity.ProductModuleContent;

@ExtendWith(MockitoExtension.class)
public class ImageUtilsTest {
class ImageUtilsTest {

@Test
void testMappingImageForProductModuleContent() {
Expand Down

0 comments on commit 965f334

Please sign in to comment.