title: What is the best way to Inject growing dependencies in the service class for unit test in java
body: <p>I have a Service class which is called from a controller(Jersey Restful api) where the service class instantiation happens.
  This Service class contains all the business logic, so we have lot of other services, dao injected in this class. In order to test this class we created a constructor where we can inject those dependencies and mock things. Now the real problem is, as this service class's dependencies are growing, the constructor arguments are increasing and is difficult to maintain. is there any other solution/alternative to this.</p>
  
  <p>I thought of creating setter method and injecting them but am not sure if that is ideal way of doing.</p>
  
  <pre><code>public ManageKitsService(NetworkService velosNetworkService, EmailService emailService, Environment environment, RestClient restClient, Properties properties, ManageKitsDao manageKitsDao, StudyDao studyDao) {
          this.NetworkService = NetworkService;
          this.emailService = emailService;
          this.environment = environment;
          this.restClient = restClient;
          this.properties = properties;
          this.manageKitsDao = manageKitsDao;
          this.studyDao = studyDao;
          .............
         ...............
          ...............
      }
  </code></pre>
  
  <p>In the unit test, we need to mock all these dependencies and pass to the constructor.
  But if some one new dependency in the service class then we need to pass that in the constructor and change all the previous unit test Compilation errors.</p>
  
  <pre><code>            private ManageKitsDao mockManageKitsDao;
              private RestClient mockRestClient;
  
              @BeforeEach
              public void setUp() throws KitException {
                 mockManageKitsDao = mock(ManageKitsDao.class);
                  mockRestClient = mock(RestClient.class);
                 ..............
                 ................
               }  
  
          @Test
          public void itShouldRevokeAssignedKit() {
          when(mockManageKitsDao.getXXXX()).thenReturn(something)
          ...........some other mocking.............
              ManageKitsService manageKitsService = new ManageKitsService(mockNetworkService, mockEmailService, mockEnvironment, mockRestClient, mockProperties, mockManageKitsDao,
                              mockStudyDao);
     assertThatCode(() -&gt; {
      manageKitsService.revokeAssignedKit(123, kitAssignment);
          }).doesNotThrowAnyException();
     }
  </code></pre>
  
  <p>Is there any best way to inject dependencies to mock things and write unit test.
  Help is appreciated!</p>