diff options
author | zhangab <zhanganbing@chinamobile.com> | 2018-03-27 20:27:03 +0800 |
---|---|---|
committer | zhangab <zhanganbing@chinamobile.com> | 2018-03-27 20:27:08 +0800 |
commit | fc8d3f3e4def8b976b2d7c8f2b7bdeb3f838b601 (patch) | |
tree | 6924e8dd795c80845346ba7ecb84c5fb3161d741 | |
parent | 565fc0c853537fc1afd0966e59e663c869d83247 (diff) |
improve sonar coverage for uui-server
Change-Id: I9a809f3916822411e39c711ebeb51f5aebac7685
Issue-ID: USECASEUI-103
Signed-off-by: zhangab <zhanganbing@chinamobile.com>
-rw-r--r-- | server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java index 30c87b9a..4e8c3db3 100644 --- a/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java +++ b/server/src/test/java/org/onap/usecaseui/server/service/impl/AlarmsHeaderServiceImplTest.java @@ -32,6 +32,11 @@ import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import mockit.Expectations; +import mockit.Mocked; +import mockit.integration.junit4.JMockit; /** * AlarmsHeaderServiceImpl Tester. * @@ -39,20 +44,15 @@ import java.util.Date; * @since <pre>8, 2018</pre> * @version 1.0 */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = UsecaseuiServerApplication.class) -@WebAppConfiguration +@RunWith(JMockit.class) public class AlarmsHeaderServiceImplTest { - @Autowired - private AlarmsHeaderServiceImpl alarmsHeaderServiceImpl; + @Before + public void before() throws Exception { + } -@Before -public void before() throws Exception { -} - -@After -public void after() throws Exception { -} + @After + public void after() throws Exception { + } /** * @@ -60,7 +60,9 @@ public void after() throws Exception { * */ @Test -public void testSaveAlarmsHeader() throws Exception { +public void testSaveAlarmsHeader(@Mocked SessionFactory sessionFactory, + @Mocked Session session +) throws Exception { //TODO: Test goes here... AlarmsHeader a = new AlarmsHeader(); a.setEventName("a"); @@ -89,7 +91,12 @@ public void testSaveAlarmsHeader() throws Exception { a.setStartEpochMicrosec("wallet"); a.setUpdateTime(DateUtils.now()); a.setVersion("va2"); - alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); + + new Expectations() {{ + sessionFactory.openSession(); result = session; + }}; + + AlarmsHeaderServiceImpl alarmsHeaderServiceImpl = new AlarmsHeaderServiceImpl(); System.out.println(alarmsHeaderServiceImpl.saveAlarmsHeader(a)); } |