@AllArgsConstructor not working on object initialization

Viewed 482

Following is the of MyService application:

@AllArgsConstructor
public class MyService {
   @NonNull private final MyService1 myService1;
   
   //rest of code
}

I have specified the @AllArgsConstructor. When I am trying to write the unit tests for the class above it fails. Following is how I am writing the unit test:

@RunWith(Mockito.JUnitRunner.class)
public MyServiceTest {
     @Mock
     private MyService1 myService1;
     
     private MyService myService;
     @Before
     public void setUp() {
        myService = new MyService(myService1);
        //rest of code
     }
}

The error thrown is:

java: constructor MyService in class cannot be applied to given types; required: no arguments found: reason: actual and formal argument lists differ in length

But when I explicitly define a constructor in MyService, the tests pass. Can anyone help me here?

0 Answers
Related