Closed ColinHebert closed 10 years ago
The test is successful with this (inverted the definition of the mocks):
new NonStrictExpectations(){{
mockUrlConnection.getOutputStream();
result = mockOutputStream;
mockUrl.openConnection();
result = mockUrlConnection;
}};
More weird behaviour:
package test;
import mockit.Injectable;
import mockit.NonStrictExpectations;
import mockit.Tested;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import javax.net.ssl.HttpsURLConnection;
import java.io.OutputStream;
import java.net.URL;
import static org.testng.Assert.assertTrue;
class A {
private URL url;
}
public class ATest {
@Tested
private A a;
@Injectable
private URL mockUrl = null;
@Injectable
private HttpsURLConnection mockUrlConnection = null;
@Injectable
private OutputStream mockOutputStream = null;
@BeforeMethod
public void setUp() throws Exception {
new NonStrictExpectations(){{
mockUrlConnection.getOutputStream();
result = mockOutputStream;
mockUrl.openConnection();
result = mockUrlConnection;
}};
}
@Test
public void test1() throws Exception {
assertTrue(true);
}
@Test
public void test2() throws Exception {
assertTrue(true);
}
}
First test is a success, second results in
java.net.UnknownServiceException: protocol doesn't support output at java.net.URLConnection.getOutputStream(URLConnection.java:843) at test.ATest$1.
(ATest.java:32) at test.ATest.setUp(ATest.java:31)
It's a bug, thanks for the report.
I have this code which was working with jmockit 1.10, and has a strange behaviour since 1.12:
Results in