Latest Questions tagged Powermock

Browse all latest questions tagged Powermock

Published 07 Sep, 2022
Java - Mocking Logger and LoggerFactory with PowerMock and Mockito

I have the following Logger I want to mock out, but to validate log entries are getting called, not for the content. private static Logger logger = LoggerFactory.getLogger(GoodbyeController....

Published 28 Aug, 2022
Java - PowerMock and Java 8 issue: InterfaceMethodrefInfo cannot be cast to MethodrefInfo

I´m having issues while trying to execute a unit test using PowerMock with Mockito. I need PowerMockito to mock an static method. These are the versions I´m using: PowerMock 1.6.2 Mockito 1.10.19 JU...

Published 16 Sep, 2022
Java - How to undo/reset PowerMockito.mockStatic?

Assuming I have the following classes public class StaticClass { public static void staticMethod() throws SomeException { System.out.println("staticMethod"); } private StaticCla...

Published 15 Sep, 2022
Java - @PowerMockIgnore at project level

I have following error in my powermock test cases while running in Maven : java.lang.LinkageError: loader constraint violation: loader (instance of org/powermock/core/classloader/MockClassLoader) pre...

Published 15 Sep, 2022
Java - PowerMock access private static members

How I can access the following private static field foo by PowerMock. I just want to verify that Foo for example is not null and I can't refactor the code by adding getters. public class Bar{ pri...

Published 15 Sep, 2022
Java - Mocked private method with PowerMock, but underlying method still gets called

I am trying to mock out a private method that is making a JNDI call. When that method gets called from a unit test, it throws an exception^. I would like to mock-out that method for testing purposes....

Published 14 Sep, 2022
Java - doAnswer for static methods - PowerMock

One of static method I am using, it does two things. It returns some data, but it also modifies the argument object that is passed to it. This updated argument object is then used later in code. I am...

Published 12 Sep, 2022
Java - Junit Parameterized tests together with Powermock - how?

I've been trying to figure out how to run parameterized tests in Junit4 together with PowerMock. The problem is that to use PowerMock you need to decorate your test class with @RunWith(PowerMockRunn...

Published 11 Sep, 2022
Java - how to mock a URL connection

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 String urlToValidate) throws WAGNetworkExcept...

Published 08 Sep, 2022
Java - PowerMock, mock a static method, THEN call real methods on all other statics

I'm setting up mocking a class' static methods. I have to do this in a @Before-annotated JUnit setup method. My goal is to setup the class to call real methods, except for those methods I explicitly...

Published 31 Aug, 2022
Java - The type MockitoAnnotations.Mock is deprecated

I am mocking a object using @Mock annotation @Mock Customer customer; but the @Mock annotation is showing warning The type MockitoAnnotations.Mock is deprecated and my test case is failed

Published 29 Aug, 2022
Java - Testing Spring controllers using Powermock

I have a class which tests specific controller and it works fine @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = "classpath:config/test-applicationContext-config.xml") @Test...

Published 29 Aug, 2022
Java - Java PowerMockito Mocking

I'm attempting to Mock the static method and I continue to keep coming across weird behavior when trying to mock classes from java.time package. Please see my code below on attempting to...

Published 27 Aug, 2022
Java - Powermockito doNothing for method with arguments

I've developed an application in Java and I'm trying to create unit tests using Powermockito (I should add that I'm new to unit testing). I have a class called Resource which has a static method call...

Published 26 Aug, 2022
Java - How to mock Thread.sleep() with PowerMock?

How to mock Thread.sleep() with PowerMock? Sample interface and class: public interface Machine { void sleep(long millis); } public class MachineImpl implements Machine { private static f...