Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
tutn-axonivy committed Jul 18, 2024
1 parent 3ee9ae9 commit 1a6fa1b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
package com.axonivy.market.service;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.constants.ProductJsonConstants;
import com.axonivy.market.constants.ReadmeConstants;
import com.axonivy.market.entity.Product;
import com.axonivy.market.github.model.MavenArtifact;
import com.axonivy.market.github.service.GitHubService;
import com.axonivy.market.github.service.impl.GHAxonIvyProductRepoServiceImpl;
import com.fasterxml.jackson.databind.JsonNode;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kohsuke.github.*;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.when;

import java.io.ByteArrayInputStream;
import java.io.IOException;
Expand All @@ -26,9 +17,29 @@
import java.util.Iterator;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.kohsuke.github.GHContent;
import org.kohsuke.github.GHOrganization;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GHTag;
import org.kohsuke.github.PagedIterable;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.Spy;
import org.mockito.junit.jupiter.MockitoExtension;

import com.axonivy.market.constants.CommonConstants;
import com.axonivy.market.constants.ProductJsonConstants;
import com.axonivy.market.constants.ReadmeConstants;
import com.axonivy.market.entity.Product;
import com.axonivy.market.enums.Language;
import com.axonivy.market.github.model.MavenArtifact;
import com.axonivy.market.github.service.GitHubService;
import com.axonivy.market.github.service.impl.GHAxonIvyProductRepoServiceImpl;
import com.fasterxml.jackson.databind.JsonNode;

@ExtendWith(MockitoExtension.class)
class GHAxonIvyProductRepoServiceImplTest {
Expand Down Expand Up @@ -205,7 +216,7 @@ void testGetReadmeAndProductContentsFromTag() throws IOException {
assertEquals("com.axonivy.utils.bpmnstatistic", result.getGroupId());
assertEquals("bpmn-statistic", result.getArtifactId());
assertEquals("iar", result.getType());
assertEquals("Test README", result.getDescription());
assertEquals("Test README", result.getDescription().get(Language.EN.getValue()));
assertEquals("Demo content", result.getDemo());
assertEquals("Setup content (https://raw.githubusercontent.com/image.png)", result.getSetup());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify;

@SpringBootTest(properties = { "marketPlace-installation-url=D:/marketplace-installation.json" })
@SpringBootTest(properties = { "MARKETPLACE_INSTALLATION_URL=D:/marketplace-installation.json" })
class SchedulingTasksTest {

@SpyBean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,10 @@ void testGetVersionsFromArtifactDetails() {
versionFromArtifact.add("10.0.19");
versionFromArtifact.add("10.0.20");
versionFromArtifact.add("10.0.21");
versionFromArtifact.add("10.0.22");
versionFromArtifact.add("10.0.23");
versionFromArtifact.add("10.0.24");
versionFromArtifact.add("10.0.25");

try (MockedStatic<XmlReaderUtils> xmlUtils = Mockito.mockStatic(XmlReaderUtils.class)) {
xmlUtils.when(() -> XmlReaderUtils.readXMLFromUrl(Mockito.anyString())).thenReturn(versionFromArtifact);
Expand Down

0 comments on commit 1a6fa1b

Please sign in to comment.