Questions tagged [mockstatic]

24 questions
0
votes
1 answer

MockedStatic with arguments says "Misplaced or misused argument matcher detected"

I have one class where one public non-static method executes a static method call inside requires to mock static when I tried to test in junit with mockito. What did i do wrong? class DummyClass { public boolean filter(CharSequence source) { …
0
votes
0 answers

Debugger Highlights wrong lines When making unit tests using Mockito inline mock maker.(Mocking Constructor with MockedStatic)

I am facing a weird behavior When using mockedstatic with mockedConstruction. Debugger highlights wrong lines but If I added System.out.println I see that the code executes properly. here is the code public class Example { private AnotherClass…
Rehab Reda
  • 193
  • 7
  • 16
0
votes
0 answers

org.powermock.api.mockito.ClassNotPreparedException at PowerMockito.mockStatic() when upgrading jdk8 to JDK11

I am using PowerMockito.mockStatic(LogServiceImpl) in my unit test code written in SPOCK framework. Even i declared @PrepareForTest([LogServiceImpl]) at class level, i am getting org.powermock.api.mockito.ClassNotPreparedException. Earlier it was…
Shobana
  • 41
  • 4
0
votes
1 answer

Junit Rule with PowerMockito : ClassNotPreparedException

I working on testing some static classes using PowerMockito, and sometimes the test fail, in order to overcame this issue a create a customize JUnit Rule to re-run the failure tests. The rule works fine but whenever the test is re-executed , it's…
Ak.tech
  • 71
  • 1
  • 5
0
votes
1 answer

ResourceBundle.getBundle returning actual object in spite of mockStatic and when() directing otherwise

I'm creating tests over existing classes. A number of them have a resource bundle defined as a private final field that's initialized when the object is created via new. I declare a mocked ResourceBundle, use PowerMock's mockStatic method to enable…
0
votes
2 answers

Powermock, mockStatic of UUID.getRandom works in test class but doesn't in the class tested

Strange case: using Powermock to mock out UUID.getRandom(). This works within the JUnit test class but when the class under test (a Filter, if that matters) calls UUID.getRandom, a unique UUID is produced. Simple test…
Lonnie Lewis
  • 65
  • 1
  • 6
0
votes
1 answer

IllegalStateException complaining PowerMockRule being loaded by powermock classloader rather than system classloader

@RunWith(PowerMockRunner.class) @PrepareForTest(StaticMethodsHolder.class) public class MockNTestStaticMethodsHolder { @Rule public PowerMockRule rule = new PowerMockRule(); @Test public void staticSvcClientMethod () { // blah blah blah …
Blessed Geek
  • 21,058
  • 23
  • 106
  • 176
0
votes
1 answer

PowerMock throw initialzationError when a class's static method return same a same class's object

An initializationError is thrown. I'm using powermock 1.6.4 and javassist-3.20.0. It seems I can't mock and mockstatic on the same class (at the same time). interface B { public static B getA() { return new B() { }; } } a test…
user2201253
  • 125
  • 2
  • 5
-1
votes
1 answer

static mocking is already registered in the current thread

@RunWith(MockitoJUnitRunner.class) public class MyTest { private AutoCloseable autoCloseable; @BeforeEach void init() throws InterruptedException { autoCloseable = MockitoAnnotations.openMocks(this); } @AfterEach public void…
Walking Corpse
  • 107
  • 7
  • 31
  • 49
1
2