BAEL-3868 - Fix the integrations tests in mocks
This commit is contained in:
parent
b1d31f9bd5
commit
af0fc5f058
|
@ -15,5 +15,5 @@ public interface ExpectationsCollaborator {
|
||||||
void methodForArgThat(Object o);
|
void methodForArgThat(Object o);
|
||||||
String methodReturnsString();
|
String methodReturnsString();
|
||||||
int methodReturnsInt();
|
int methodReturnsInt();
|
||||||
Object methodForDelegate(int i);
|
int methodForDelegate(int i);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,21 +1,21 @@
|
||||||
package com.baeldung.jmockit;
|
package com.baeldung.jmockit;
|
||||||
|
|
||||||
import com.baeldung.jmockit.ExpectationsCollaborator;
|
import static org.junit.Assert.assertEquals;
|
||||||
import com.baeldung.jmockit.Model;
|
import static org.junit.Assert.fail;
|
||||||
import mockit.Delegate;
|
|
||||||
import mockit.Expectations;
|
import java.util.ArrayList;
|
||||||
import mockit.Mocked;
|
import java.util.List;
|
||||||
import mockit.Verifications;
|
|
||||||
import mockit.integration.junit4.JMockit;
|
|
||||||
import org.hamcrest.BaseMatcher;
|
import org.hamcrest.BaseMatcher;
|
||||||
import org.hamcrest.Description;
|
import org.hamcrest.Description;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import mockit.Delegate;
|
||||||
import java.util.List;
|
import mockit.Expectations;
|
||||||
|
import mockit.Mocked;
|
||||||
import static org.junit.Assert.assertEquals;
|
import mockit.Verifications;
|
||||||
|
import mockit.integration.junit4.JMockit;
|
||||||
|
|
||||||
@RunWith(JMockit.class)
|
@RunWith(JMockit.class)
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -112,17 +112,16 @@ public class ExpectationsIntegrationTest {
|
||||||
result = "foo";
|
result = "foo";
|
||||||
result = new Exception();
|
result = new Exception();
|
||||||
result = "bar";
|
result = "bar";
|
||||||
mock.methodReturnsInt();
|
|
||||||
result = new int[]{1, 2, 3};
|
|
||||||
mock.methodReturnsString();
|
|
||||||
returns("foo", "bar");
|
returns("foo", "bar");
|
||||||
mock.methodReturnsInt();
|
mock.methodReturnsInt();
|
||||||
|
result = new int[]{1, 2, 3};
|
||||||
result = 1;
|
result = 1;
|
||||||
}};
|
}};
|
||||||
|
|
||||||
assertEquals("Should return foo", "foo", mock.methodReturnsString());
|
assertEquals("Should return foo", "foo", mock.methodReturnsString());
|
||||||
try {
|
try {
|
||||||
mock.methodReturnsString();
|
mock.methodReturnsString();
|
||||||
|
fail("Shouldn't reach here");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// NOOP
|
// NOOP
|
||||||
}
|
}
|
||||||
|
@ -139,8 +138,9 @@ public class ExpectationsIntegrationTest {
|
||||||
public void testDelegate(@Mocked ExpectationsCollaborator mock) {
|
public void testDelegate(@Mocked ExpectationsCollaborator mock) {
|
||||||
new Expectations() {{
|
new Expectations() {{
|
||||||
mock.methodForDelegate(anyInt);
|
mock.methodForDelegate(anyInt);
|
||||||
result = new Delegate() {
|
|
||||||
public int delegate(int i) throws Exception {
|
result = new Delegate<Integer>() {
|
||||||
|
int delegate(int i) throws Exception {
|
||||||
if (i < 3) {
|
if (i < 3) {
|
||||||
return 5;
|
return 5;
|
||||||
} else {
|
} else {
|
||||||
|
@ -153,6 +153,7 @@ public class ExpectationsIntegrationTest {
|
||||||
assertEquals("Should return 5", 5, mock.methodForDelegate(1));
|
assertEquals("Should return 5", 5, mock.methodForDelegate(1));
|
||||||
try {
|
try {
|
||||||
mock.methodForDelegate(3);
|
mock.methodForDelegate(3);
|
||||||
|
fail("Shouldn't reach here");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue