Code: Select all
@RestController
@RequestMapping("document")
public class DocumentController {
private final Logger logger = LoggerFactory.getLogger(DocumentController.class);
private final PtfCommonService ptfCommonService;
private final DocumentService documentService;
@Autowired
public DocumentController(PtfCommonService ptfCommonService, DocumentService documentService) {
this.ptfCommonService = ptfCommonService;
this.documentService = documentService;
}
@RequestMapping(value = "/create", method = RequestMethod.POST, produces = "application/json")
public String create(@RequestBody String documentInfo) {
System.out.println(this.documentService.getClass());
return new Gson().toJson(this.documentService.createDocument(documentInfo));
}
}
Code: Select all
@Lazy
@Service
public class DocumentServiceImpl implements DocumentService {
@Override
public JsonResponse createDocument(String documentInfo) {
return saveDocument(documentInfo, false);
}
}
enthält
Code: Select all
@RunWith(MockitoJUnitRunner.class)
//@ContextConfiguration(value = "classpath:applicationContext.xml")
public class DocumentControllerTest extends TestCase {
@Mock
DocumentService documentService;
@InjectMocks
DocumentController documentController;
@Before
@Override
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
/**
* Test method to verify the functionality of createDocumnet controller method.
*/
@Test
public void createDocumentTest () {
String documentInfo = "testInfo";
JsonResponse jsonResp = new JsonResponse();
jsonResp.setMessage("OK");
jsonResp.setStatus("OK");
jsonResp.setSuccess(true);
// Mockito.when(documentService.createDocument(Mockito.anyString())).thenReturn(jsonResp);
Mockito.when(documentService.createDocument(documentInfo)).thenReturn(jsonResp);
String jsonResponse = documentController.create(documentInfo);
System.out.println(jsonResponse);
assertEquals(jsonResponse, jsonResponse);
}
}
< /code>
Dies ist die Ausnahme, die ich bekomme, wenn ich den Test ausführe: < /p>
unnecessary Mockito stubbings(com.persivia.ptf.patientservice.controller.DocumentControllerTest) Time elapsed: 0.511 sec