Hi I have a method that takes an URL as an input and determines if it is reachable. Heres the code for that:
public static boolean isUrlAccessible(final Str
In order to mock java.net.URL class through mockito library, you need to perform the following steps:
mock-maker-inline text into the file. code:
package myproject;
import org.junit.Test;
import java.net.HttpURLConnection;
import java.net.URL;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class Test {
@Test
public void test() throws Exception {
URL url = mock(URL.class);
HttpURLConnection huc = mock(HttpURLConnection.class);
when(url.openConnection()).thenReturn(huc);
assertTrue(url.openConnection() instanceof HttpURLConnection);
}
}