Java Examples for org.powermock.api.mockito.PowerMockito.whenNew

The following java examples will help you to understand the usage of org.powermock.api.mockito.PowerMockito.whenNew. These source code samples are taken from different open source projects.

Example 1
Project: mockito-cookbook-master  File: TaxFactorCalculatorTestNgTest.java View source code
@Test
public void should_calculate_tax_factor() throws Exception {
    // given
    whenNew(TaxWebService.class).withNoArguments().thenReturn(taxWebService);
    when(taxWebService.calculateTaxFactorFor(any(Person.class))).thenReturn(TAX_FACTOR);
    // when
    double taxFactorForPerson = systemUnderTest.calculateTaxFactorFor(new Person());
    // then
    then(taxFactorForPerson).isEqualTo(TAX_FACTOR);
}
Example 2
Project: powermock-master  File: Github510Test.java View source code
@Test
public void testInterfaceStaticCallsConstructor() throws Exception {
    final String value = "Hi Man";
    ConstructorObject constructorObject = mock(ConstructorObject.class);
    when(constructorObject.sayHello()).thenReturn(value);
    whenNew(ConstructorObject.class).withNoArguments().thenReturn(constructorObject);
    assertThat(classUsesInterface.createAndSay()).isEqualTo(value);
}
Example 3
Project: camel-smslib-master  File: SmslibEndpointTest.java View source code
@Before
public void setUp() throws Exception {
    mockCServiceFactory = mock(CServiceFactory.class);
    whenNew(CServiceFactory.class).withNoArguments().thenReturn(mockCServiceFactory);
    mockSmslibService = mock(SmslibService.class);
    whenNew(SmslibService.class).withArguments(mockCServiceFactory, URI, REMAINING, NO_PARAMS).thenReturn(mockSmslibService);
    endpoint = new SmslibEndpoint(URI, null, REMAINING, NO_PARAMS);
}
Example 4
Project: overlap2d-master  File: BootstrapPluginsTest.java View source code
@Before
public void setUp() throws Exception {
    initMocks(this);
    PowerMockito.mockStatic(Overlap2DFacade.class);
    PowerMockito.when(Overlap2DFacade.getInstance()).thenReturn(overlap2DFacade);
    whenNew(PluginManager.class).withNoArguments().thenReturn(pluginManager);
    given(overlap2DFacade.retrieveProxy(ProjectManager.NAME)).willReturn(projectManager);
    bootstrapPlugins = new BootstrapPlugins();
}
Example 5
Project: Magnet-master  File: SimpleAnimatorTest.java View source code
@Before
public void setUp() throws Exception {
    view = mock(View.class);
    WeakReference viewWeakReference = mock(WeakReference.class);
    whenNew(WeakReference.class).withArguments(view).thenReturn(viewWeakReference);
    doReturn(view).when(viewWeakReference).get();
    simpleAnimator = new SimpleAnimator(view, 1);
    mockStatic(AnimationUtils.class);
    animation = mock(Animation.class);
    doReturn(animation).when(AnimationUtils.class, "loadAnimation", null, 1);
}
Example 6
Project: ari-toolkit-master  File: TmdbClientTest.java View source code
@Before
public void setUp() throws Exception {
    when(mockTmdbClientProperties.getTmdbServerUrl()).thenReturn("TMDB server URL");
    when(mockTmdbClientProperties.getTrustStoreFilename()).thenReturn("trustStoreFilename");
    when(mockTmdbClientProperties.getTrustStorePassphrase()).thenReturn("trustStorePassphrase");
    when(mockTmdbClientProperties.getTmdbSocketTimeOut()).thenReturn(1000);
    whenNew(TLSContext.class).withArguments("trustStoreFilename", "trustStorePassphrase").thenReturn(mockTlsContext);
    when(mockTlsContext.createHttpsUrlConnection("TMDB server URL/lookupKey.xml", 1000)).thenReturn(mockConnection);
    stringInputStream = new ByteArrayInputStream("noticeXml".getBytes());
    when(mockConnection.getInputStream()).thenReturn(stringInputStream);
    whenNew(TmNoticeXmlParser.class).withNoArguments().thenReturn(mockTmNoticeXmlParser);
    when(mockTmNoticeXmlParser.parse("noticeXml")).thenReturn(mockTmNotice);
    whenNew(TmdbClientProperties.class).withArguments("tmdb.properties").thenReturn(mockTmdbClientProperties);
    tmdbClient = new TmdbClient();
}
Example 7
Project: viskell-master  File: MenuActionsTest.java View source code
@Test
public void showPreferencesTest() throws Exception {
    // Mocks
    ToplevelPane mockToplevelPane = mock(ToplevelPane.class);
    PreferencesWindow mockPreferencesWindow = mock(PreferencesWindow.class);
    whenNew(PreferencesWindow.class).withArguments(any()).thenReturn(mockPreferencesWindow);
    // UUT
    MenuActions menuActions = new MenuActions(mockMainOverlay, mockToplevelPane);
    // Test
    menuActions.showPreferences(mockEvent);
    // verify
    verify(mockPreferencesWindow, times(1)).show();
}
Example 8
Project: elmis-master  File: RequisitionEventServiceTest.java View source code
@Test
public void shouldTriggerNotifyOnEventService() throws Exception {
    Rnr requisition = make(a(defaultRequisition));
    RequisitionStatusChangeEvent event = mock(RequisitionStatusChangeEvent.class);
    whenNew(RequisitionStatusChangeEvent.class).withArguments(requisition, notificationServices).thenReturn(event);
    service.notifyForStatusChange(requisition);
    verify(eventService).notify(event);
}
Example 9
Project: jmeter-plugins-master  File: HtmlUnitDriverConfigTest.java View source code
@Test
public void shouldCreateHtmlUnit() throws Exception {
    HtmlUnitDriver mockHtmlUnitDriver = Mockito.mock(HtmlUnitDriver.class);
    whenNew(HtmlUnitDriver.class).withParameterTypes(Capabilities.class).withArguments(isA(Capabilities.class)).thenReturn(mockHtmlUnitDriver);
    final HtmlUnitDriver browser = config.createBrowser();
    assertThat(browser, is(mockHtmlUnitDriver));
    verifyNew(HtmlUnitDriver.class, times(1)).withArguments(isA(Capabilities.class));
}
Example 10
Project: jrs-rest-java-client-master  File: ThumbnailsServiceTest.java View source code
@Test
public /**
     * for {@link ThumbnailsService#thumbnail()}
     */
void should_invoke_proper_single_thumbnail_adapter_constructor_and_pass_proper_session_storage_instance() throws Exception {
    // Given
    whenNew(SingleThumbnailAdapter.class).withArguments(sessionStorageMock).thenReturn(singleThumbnailAdapterMock);
    // When
    ThumbnailsService thumbnailsService = new ThumbnailsService(sessionStorageMock);
    SingleThumbnailAdapter retrieved = thumbnailsService.thumbnail();
    // Then
    assertNotNull(retrieved);
    assertSame(retrieved, singleThumbnailAdapterMock);
    verifyNew(SingleThumbnailAdapter.class, times(1)).withArguments(sessionStorageMock);
}
Example 11
Project: tripping-dangerzone-master  File: Utils.java View source code
@SuppressWarnings(value = "rawtypes")
static void setupMockThreadPool() throws Exception {
    ThreadPool mockTP = mock(ThreadPool.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) {
            Object[] args = invocation.getArguments();
            ((Runnable) args[0]).run();
            return null;
        }
    }).when(mockTP).addJob((any(Runnable.class)));
    whenNew(ThreadPool.class).withArguments(anyInt()).thenReturn(mockTP);
}