Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve tests for methods "getJson" #136

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand All @@ -20,7 +19,6 @@
import java.util.jar.Manifest;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
Expand Down Expand Up @@ -64,7 +62,7 @@

@RunWith(PowerMockRunner.class)
@PrepareForTest({HttpClients.class, PluginManager.class, HttpClientContext.class, URIUtils.class, HttpHost.class,
URI.class, FileUtils.class, URL.class, IOUtils.class, Files.class, HttpClientBuilder.class})
URI.class, FileUtils.class, URL.class, Files.class, HttpClientBuilder.class})
@PowerMockIgnore({"javax.net.ssl.*","javax.security.*", "javax.net.*"})
public class PluginManagerTest {
private PluginManager pm;
Expand Down Expand Up @@ -774,21 +772,19 @@ public void outputPluginReplacementInfoTest() throws Exception {
}

@Test
public void getJsonURLExceptionTest() {
public void deprecatedGetJsonThrowsExceptionForMalformedURL() {
assertThatThrownBy(() -> pm.getJson("htttp://ftp-chi.osuosl.org/pub/jenkins/updates/current/update-center.json"))
.isInstanceOf(UpdateCenterInfoRetrievalException.class);
.isInstanceOf(UpdateCenterInfoRetrievalException.class)
.hasMessage("Malformed url for update center");
}

@Test
public void getJsonURLIOTest() throws IOException{
mockStatic(IOUtils.class);

when(IOUtils.toString(any(URL.class), any(Charset.class))).thenThrow(IOException.class);

public void getJsonThrowsExceptionWhenUrlDoesNotExists() throws IOException{
pm.setCm(new CacheManager(folder.newFolder().toPath(), false));

assertThatThrownBy(() -> pm.getJson(new URL("http://ftp-chi.osuosl.org/pub/jenkins/updates/current/update-center.json"), "update-center"))
.isInstanceOf(UpdateCenterInfoRetrievalException.class);
assertThatThrownBy(() -> pm.getJson(new File("does/not/exist").toURI().toURL(), "update-center"))
.isInstanceOf(UpdateCenterInfoRetrievalException.class)
.hasMessage("Error getting update center json");
}

@Test
Expand Down