From 8267cef97360051e72232ff86a3174c2875df411 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sun, 28 Apr 2019 14:38:03 +0200 Subject: [PATCH] improved code coverage for ShareResource --- .../web/rest/ShareResourceIntTest.java | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/hostsharing/hsadminng/web/rest/ShareResourceIntTest.java b/src/test/java/org/hostsharing/hsadminng/web/rest/ShareResourceIntTest.java index 261aba5a..e4e99931 100644 --- a/src/test/java/org/hostsharing/hsadminng/web/rest/ShareResourceIntTest.java +++ b/src/test/java/org/hostsharing/hsadminng/web/rest/ShareResourceIntTest.java @@ -37,6 +37,7 @@ import static org.hamcrest.Matchers.hasItem; import static org.hostsharing.hsadminng.web.rest.TestUtil.createFormattingConversionService; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; + /** * Test class for the ShareResource REST controller. * @@ -109,7 +110,7 @@ public class ShareResourceIntTest { /** * Create an entity for this test. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ @@ -130,7 +131,7 @@ public class ShareResourceIntTest { /** * Create a persistent entity related to the given persistent membership for testing purposes. - * + *

* This is a static method, as tests for other entities might also need it, * if they test an entity which requires the current entity. */ @@ -180,10 +181,10 @@ public class ShareResourceIntTest { @Test @Transactional - public void createShareWithExistingId() throws Exception { + public void createShareWithIdForNonExistingEntity() throws Exception { int databaseSizeBeforeCreate = shareRepository.findAll().size(); - // Create the Share with an existing ID + // Create the Share with an ID share.setId(1L); ShareDTO shareDTO = shareMapper.toDto(share); @@ -198,6 +199,27 @@ public class ShareResourceIntTest { assertThat(shareList).hasSize(databaseSizeBeforeCreate); } + @Test + @Transactional + public void createShareWithExistingExistingEntity() throws Exception { + // Initialize the database + shareRepository.saveAndFlush(share); + int databaseSizeBeforeCreate = shareRepository.findAll().size(); + + // Create the Share with the ID of an existing ID + ShareDTO shareDTO = shareMapper.toDto(share); + + // An entity with an existing ID cannot be created, so this API call must fail + restShareMockMvc.perform(post("/api/shares") + .contentType(TestUtil.APPLICATION_JSON_UTF8) + .content(TestUtil.convertObjectToJsonBytes(shareDTO))) + .andExpect(status().isBadRequest()); + + // Validate the Share in the database + List assetList = shareRepository.findAll(); + assertThat(assetList).hasSize(databaseSizeBeforeCreate); + } + @Test @Transactional public void checkDocumentDateIsRequired() throws Exception { @@ -291,7 +313,7 @@ public class ShareResourceIntTest { .andExpect(jsonPath("$.[*].quantity").value(hasItem(DEFAULT_QUANTITY))) .andExpect(jsonPath("$.[*].remark").value(hasItem(DEFAULT_REMARK.toString()))); } - + @Test @Transactional public void getShare() throws Exception {