Refine search
@RunWith(MockitoJUnitRunner.class) public class GetUserDetailsTest { @Mock private UserRepository mockUserRepository; @Mock private ThreadExecutor mockThreadExecutor; @Mock private PostExecutionThread mockPostExecutionThread; @Rule public ExpectedException expectedException = ExpectedException.none();
public Object process(Mock annotation, Field field) { MockSettings mockSettings = Mockito.withSettings(); if (annotation.extraInterfaces().length > 0) { // never null mockSettings.extraInterfaces(annotation.extraInterfaces()); } if ("".equals(annotation.name())) { mockSettings.name(field.getName()); } else { mockSettings.name(annotation.name()); } // see @Mock answer default value mockSettings.defaultAnswer(annotation.answer().get()); return Mockito.mock(field.getType(), mockSettings); } }
public static Object processAnnotationForMock(Mock annotation, Class<?> type, String name) { MockSettings mockSettings = Mockito.withSettings(); if (annotation.extraInterfaces().length > 0) { // never null mockSettings.extraInterfaces(annotation.extraInterfaces()); } if ("".equals(annotation.name())) { mockSettings.name(name); } else { mockSettings.name(annotation.name()); } if(annotation.serializable()){ mockSettings.serializable(); } if(annotation.stubOnly()){ mockSettings.stubOnly(); } if(annotation.lenient()){ mockSettings.lenient(); } // see @Mock answer default value mockSettings.defaultAnswer(annotation.answer()); return Mockito.mock(type, mockSettings); } }
@RunWith(MockitoJUnitRunner.StrictStubs.class) public class ListEnvironmentsTest { private static final String CLUSTER = "cluster"; private static final String ENVIRONMENT_NAME_PREFIX = "environmentNamePrefix"; @Mock private HttpServletRequest request; @Mock private DataService dataService; @Mock private ListEnvironmentsMapper mapper; @Mock private ApiGatewayRequestContext context; @Mock private ListEnvironmentsRequest dsRequest; @Mock private ListEnvironmentsResponse dsResponse; @Mock private ListEnvironments.ListEnvironmentsResponse feResponse; @Mock private RequestPagination pagination; @InjectMocks private ListEnvironments api;
@RunWith(MockitoJUnitRunner.class) public static class TestUnit { @Mock HttpResponse proxyResp; @Mock HttpRequestMessage request; @Test public void testIsValidResponseHeader() { Assert.assertTrue(isValidResponseHeader(HttpHeaderNames.get("test"))); Assert.assertFalse(isValidResponseHeader(HttpHeaderNames.get("Keep-Alive"))); Assert.assertFalse(isValidResponseHeader(HttpHeaderNames.get("keep-alive"))); } } }
@RunWith(RobolectricTestRunner.class) public class MockitoInjectMocksTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @Mock TextView textView; @InjectMocks Activity activity = Robolectric.setupActivity(Activity.class); @Test public void testInjection() { activity.finish(); } }
public class SimpleTest { @Rule public final DaggerMockRule<MyTestComponent> rule = new DaggerMockRule<>(MyTestComponent.class, new MyModule()) .set(new DaggerMockRule.ComponentSetter<MyTestComponent>() { @Override public void setComponent(MyTestComponent component) { mainService = component.mainService(); } }); @Mock MyService myService; private MainService mainService; @Test public void testConstructorArgs() { assertThat(mainService).isNotNull(); assertThat(mainService.getMyService()).isSameAs(myService); } }
public class PluginWriterTest { @Mock private SystemEnvironment systemEnvironment; @Mock private GoFileSystem goFileSystem; @InjectMocks private PluginWriter pluginWriter = new PluginWriter(systemEnvironment, goFileSystem); @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder();
@Mock private SecurityService securityService; @Mock private Message message; @Mock private ServerConnection serverConnection; @Mock private InternalCache cache; @Mock private Part regionNamePart; @Mock private Message responseMessage; @InjectMocks private GetClientPartitionAttributesCommand66 getClientPartitionAttributesCommand66;
@Override public Object getParameterValue(Parameter parameter) { Mock annotation = parameter.getAnnotation(Mock.class); MockSettings settings = Mockito.withSettings(); if (annotation.extraInterfaces().length > 0) { settings.extraInterfaces(annotation.extraInterfaces()); } if (annotation.serializable()) { settings.serializable(); } settings.name(annotation.name().isEmpty() ? parameter.getName() : annotation.name()); settings.defaultAnswer(annotation.answer()); return Mockito.mock(parameter.getType(), settings); } }
private String getMockName(Parameter parameter) { String explicitMockName = parameter.getAnnotation(Mock.class).name().trim(); if (!explicitMockName.isEmpty()) { return explicitMockName; } else if (parameter.isNamePresent()) { return parameter.getName(); } return null; }
@RunWith(MockitoJUnitRunner.class) public class StartDeploymentTest { private static final String ENVIRONMENT_NAME = "TestEnvironment"; private static final String ENVIRONMENT_REVISION_ID = "1"; @Mock private HttpServletRequest request; @Mock private DataService dataService; @Mock private StartDeploymentMapper mapper; @Mock private ApiGatewayRequestContext context; @InjectMocks private StartDeployment api;
@SuppressWarnings("unchecked") @RunWith(RobolectricTestRunner.class) @Config(manifest = Config.NONE, sdk = 18) public class RequestBuilderTest { @Rule public TearDownGlide tearDownGlide = new TearDownGlide(); @Mock private RequestListener<Object> listener1; @Mock private RequestListener<Object> listener2; @Mock private Target<Object> target; @Mock private GlideContext glideContext; @Mock private RequestManager requestManager; @Captor private ArgumentCaptor<SingleRequest<Object>> requestCaptor; private Glide glide; private Application context;
public class SimpleTest { @Rule public final DaggerMockRule<MyComponent> rule = new DaggerMockRule<>(MyComponent.class, new MyModule()) .set(new DaggerMockRule.ComponentSetter<MyComponent>() { @Override public void setComponent(MyComponent component) { mainService = component.mainService(); } }); @Mock MyService myService; private MainService mainService; @Test public void testConstructorArgs() { assertThat(mainService).isNotNull(); assertThat(mainService.getMyService()).isSameAs(myService); } }