diff --git a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java index 6dc1a464816..e256f677d8b 100644 --- a/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java +++ b/apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java @@ -30,6 +30,7 @@ import com.ctrip.framework.apollo.portal.environment.Env; import com.ctrip.framework.apollo.portal.spi.UserInfoHolder; +import org.assertj.core.util.Files; import org.assertj.core.util.Lists; import org.junit.Test; import org.mockito.InjectMocks; @@ -82,11 +83,9 @@ public class ConfigsExportServiceTest extends AbstractUnitTest { @Test public void testNamespaceExportImport() throws FileNotFoundException { - String filePath = "/tmp/apollo.zip"; - File file = new File(filePath); - if (file.exists()) { - file.delete(); - } + File temporaryFolder = Files.newTemporaryFolder(); + temporaryFolder.deleteOnExit(); + String filePath = temporaryFolder + File.separator + "export.zip"; //export config UserInfo userInfo = genUser(); @@ -152,7 +151,7 @@ public void testNamespaceExportImport() throws FileNotFoundException { when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, false)).thenReturn(app2Cluster1Namespace); when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, false)).thenReturn(app2Cluster2Namespace); - FileOutputStream fileOutputStream = new FileOutputStream("/tmp/apollo.zip"); + FileOutputStream fileOutputStream = new FileOutputStream(filePath); configsExportService.exportData(fileOutputStream, Lists.newArrayList(Env.DEV)); @@ -171,7 +170,7 @@ public void testNamespaceExportImport() throws FileNotFoundException { HttpStatusCodeException itemNotFoundException = new HttpClientErrorException(HttpStatus.NOT_FOUND); when(itemService.loadItem(any(), any(), any(), any(), anyString())).thenThrow(itemNotFoundException); - FileInputStream fileInputStream = new FileInputStream("/tmp/apollo.zip"); + FileInputStream fileInputStream = new FileInputStream(filePath); ZipInputStream zipInputStream = new ZipInputStream(fileInputStream); try {