diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java b/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java index a976c3623fc0..b4a304ae5400 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/RepositoryHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -264,10 +264,7 @@ public class RepositoryHelper { parser.parse(new InputSource(reader), handler); return handler.getPluginsList(); } - catch (ParserConfigurationException e) { - throw new IOException(e); - } - catch (SAXException e) { + catch (ParserConfigurationException | SAXException | RuntimeException e) { throw new IOException(e); } finally { diff --git a/platform/platform-tests/testSrc/com/intellij/ide/plugins/RepositoryHelperTest.java b/platform/platform-tests/testSrc/com/intellij/ide/plugins/RepositoryHelperTest.java index 0f9bafad68de..7e951d760c15 100644 --- a/platform/platform-tests/testSrc/com/intellij/ide/plugins/RepositoryHelperTest.java +++ b/platform/platform-tests/testSrc/com/intellij/ide/plugins/RepositoryHelperTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,9 +16,8 @@ package com.intellij.ide.plugins; import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.util.io.IoTestUtil; -import org.junit.After; -import org.junit.Before; +import com.intellij.testFramework.rules.TempDirectory; +import org.junit.Rule; import org.junit.Test; import java.io.File; @@ -28,17 +27,7 @@ import java.util.List; import static org.junit.Assert.assertEquals; public class RepositoryHelperTest { - private File myTempFile; - - @Before - public void setUp() throws Exception { - myTempFile = IoTestUtil.createTestFile("repo.xml"); - } - - @After - public void tearDown() throws Exception { - FileUtil.delete(myTempFile); - } + @Rule public TempDirectory tempDir = new TempDirectory(); @Test(expected = IOException.class) public void testEmpty() throws IOException { @@ -51,6 +40,12 @@ public class RepositoryHelperTest { assertEquals(0, list.size()); } + @Test(expected = IOException.class) + public void testFormatErrors() throws IOException { + List list = loadPlugins("42"); + assertEquals(0, list.size()); + } + @Test public void testFullFormat() throws IOException { List list = loadPlugins( @@ -112,8 +107,9 @@ public class RepositoryHelperTest { } private List loadPlugins(String data) throws IOException { - FileUtil.writeToFile(myTempFile, data); - String url = myTempFile.toURI().toURL().toString(); + File tempFile = tempDir.newFile("repo.xml"); + FileUtil.writeToFile(tempFile, data); + String url = tempFile.toURI().toURL().toString(); return RepositoryHelper.loadPlugins(url, null); } -} +} \ No newline at end of file