Skip to content

Delete of unnecesary Autowired - DocumentController #841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.itachallenge.document.config.OpenApiConfig;
import com.itachallenge.document.service.DocumentService;
import io.swagger.v3.oas.models.OpenAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -14,7 +12,6 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.HashMap;
import java.util.Map;

Expand All @@ -25,20 +22,12 @@ public class DocumentController {

private final OpenApiConfig openApiConfig;
private final DocumentService documentService;

@Autowired
private Environment env;

@Value("${spring.application.version}")
private String version;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it deleted?


@Value("${spring.application.name}")
private String appName;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it deleted?


@Autowired
public DocumentController(OpenApiConfig openApiConfig, DocumentService documentService) {
public DocumentController(OpenApiConfig openApiConfig, DocumentService documentService, Environment env) {
this.openApiConfig = openApiConfig;
this.documentService = documentService;
this.env = env;
}

@GetMapping(value = "/api-docs/{apiname}", produces = {"application/json"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,13 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.util.ReflectionTestUtils;

import java.util.Map;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

Expand All @@ -40,8 +37,7 @@ class DocumentControllerTest {
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
documentController = new DocumentController(openApiConfig, documentService);
ReflectionTestUtils.setField(documentController, "env", env);
documentController = new DocumentController(openApiConfig, documentService, env);
}

@Test
Expand Down
Loading