Questions tagged [mockito-inline]

14 questions
5
votes
4 answers

How to use mockito-inline with Spring-Boot?

Context: We are using Junit 5, Spring-Boot 2.6.3 Spring-Boot comes with its dependency on mockito-core Problem I am looking to create a mock for a static method. Mockito provides a library (mockito-inline) that allows mocking static methods,…
Mohit Kanwar
  • 2,962
  • 7
  • 39
  • 59
3
votes
1 answer

Is there a way to mock construction with mockito-inline only if the constructor arguments match?

I'm having issues getting mockito-inline to handle a case that I would encounter when using PowerMock; mocking a construction, but only when certain arguments are in the construction. For example PowerMockito.whenNew(Car.class).withArguments("Red",…
MightyDodongo
  • 101
  • 1
  • 4
3
votes
0 answers

Can mockito-inline mock private methods?

I know that Mockito (mockito-core) does not mock private, static, and final methods, but I found that mockito-inline can mock static and final methods. But I could not find whether it can or cannot mock private methods. If it is possible, can…
Asdinesh
  • 183
  • 1
  • 6
2
votes
1 answer

Mock specific method with mockito-inline not complete class

I want to mock static methods of a class. When I'm using mockito-inline, it mocks the complete class instead of mocking specific methods. My objective is that it should only mock method which I want it to be. Others should remain untouched (as it…
Booster
  • 145
  • 1
  • 1
  • 10
2
votes
1 answer

Using mockito-inline MockedConstruction to mock FileInputStream throws Could not initialize mocked construction

I'm trying to get rid of PowerMock and replace it with mockito-inline new feature Mocking object construction , as I can't refactor the old source code. One of the test classes I have is mocking FileInputStream, the class under test…
Amgad Hanafy
  • 537
  • 5
  • 15
1
vote
0 answers

ClassCastException with mockito-inline

I am using Mockito version 5.2.0. With mockito-inline, the following code throws a ClassCastException: public static void main(String[] args) { A a = mock(A.class, RETURNS_DEEP_STUBS); String str =…
cpp beginner
  • 512
  • 6
  • 23
1
vote
0 answers

MockedStatic is not mocking one static method

I am using MockedStatic in static Util.parse(string, class) method but when I am running is not mocking and its printing NULL, basically it should give me a static file as a response that I loaded before, for that I am using MockedStatic 3.4.4, or I…
EliasM
  • 737
  • 1
  • 6
  • 14
1
vote
1 answer

How to mock a constructor which is throwing a IOException with mockito-inline?

How can i mock the next lines: Workbook templateWorkBook = null; try { templateWorkBook = new XSSFWorkbook(templateWithoutEvents); } catch (IOException ex){ log.error("Error creating workbook from file"); } I was trying somethig like this but…
Laur Alex
  • 31
  • 4
1
vote
0 answers

Mockito mockStatic on InjectMocks Object

I'm using Mockito 3.6 to take advantage of their mockStatic method. I am having issue when mocking a class that is also the main class to be used for testing. public class MainClass{ private HttpClient httpClient; public String…
Dariell Bowo
  • 21
  • 1
  • 6
0
votes
2 answers

Could not initialize inline Byte Buddy mock maker. Problem when use mockito inline

I have a problem when active mockito inline. The test works perfectly in normal mode. The error is: [ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 25.556 s <<< FAILURE! - in es.ddmain.utils.FileSystemUtilsTest [ERROR]…
Blrackerd
  • 17
  • 7
0
votes
1 answer

Mockito-inline throws Stream closed exception on RandomAccesFile

I have following lines in my testing code RandomAccessFile mockRAF = mock(RandomAccessFile.class); when(mockRAF.length()).thenReturn(len); with dependency like this testImplementation "org.mockito:mockito-inline:2.8.47" and getting Stream…
0
votes
0 answers

Unable to mock the same class constructor two times with different behaviors in Junit5 Mockito-inline

I have a Java SE project and I need to add a unit test for the class "Service". public class Service { public void solve() { Source accountDataSource = new Source<>(""); while (accountDataSource.hasNext()) { for (Account…
0
votes
0 answers

Cannot stop at breakpoints (on Method under test) when debugging by testng and mockito-inline

I write a test case to test for my service (has Method Under Test - MUT) using TestNG, Mockito-inline (to mock static). My issue is: when I set breakpoints at MUT then Eclipse's cursor cannot stop at these breakpoints. If set breakpoints at test…
Son Nguyen
  • 13
  • 4
0
votes
1 answer

mockito, how to mock a class which is a member of the container class

With mockito-inline how to test static function (with stubbing other static function), or mock/stub some internal depended class? Here is the sample: Having a class Util which internally depending on java.security.MessageDigest package…
lannyf
  • 9,865
  • 12
  • 70
  • 152