Refactor tests inside the catalog-dao model 01/55001/3
authorPiotr Darosz <piotr.darosz@nokia.com>
Mon, 18 Jun 2018 10:46:35 +0000 (12:46 +0200)
committerTal Gitelman <tg851x@intl.att.com>
Tue, 24 Jul 2018 14:28:36 +0000 (14:28 +0000)
Use Hamcrest matchers to simplify getter/setter tests structure

Change-Id: Icee88395034ffb61e60a9190d2a9e77571e6fac3
Issue-ID: SDC-1434
Signed-off-by: Piotr Darosz <piotr.darosz@nokia.com>
catalog-dao/pom.xml
catalog-dao/src/main/java/org/openecomp/sdc/be/dao/model/FacetedSearchFacet.java
catalog-dao/src/test/java/org/openecomp/sdc/be/dao/model/FacetedSearchFacetTest.java
catalog-dao/src/test/java/org/openecomp/sdc/be/dao/model/FacetedSearchResult.java [new file with mode: 0644]
catalog-dao/src/test/java/org/openecomp/sdc/be/dao/model/FetchContext.java [new file with mode: 0644]
catalog-dao/src/test/java/org/openecomp/sdc/be/dao/model/GetMultipleDataResultTest.java
pom.xml

index 7186742..b0ffa4c 100644 (file)
                        <scope>test</scope>
                </dependency>
 
+               <dependency>
+                       <groupId>com.google.code.bean-matchers</groupId>
+                       <artifactId>bean-matchers</artifactId>
+                       <version>${bean-matchers.version}</version>
+                       <scope>test</scope>
+               </dependency>
+
                <dependency>
                        <groupId>org.yaml</groupId>
                        <artifactId>snakeyaml</artifactId>
index 24db9b6..c71c8ae 100644 (file)
@@ -33,6 +33,9 @@ public class FacetedSearchFacet implements Serializable {
                this.facetValue = facetValue;
        }
 
+       private FacetedSearchFacet() {
+       }
+
        public String getFacetValue() {
                return facetValue;
        }
index 79ee69b..8a02bc0 100644 (file)
@@ -1,55 +1,13 @@
 package org.openecomp.sdc.be.dao.model;
 
 import org.junit.Test;
-
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
 
 public class FacetedSearchFacetTest {
 
-       private FacetedSearchFacet createTestSubject() {
-               return new FacetedSearchFacet("", 0);
-       }
-
-       
-       @Test
-       public void testGetFacetValue() throws Exception {
-               FacetedSearchFacet testSubject;
-               String result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getFacetValue();
-       }
-
-       
-       @Test
-       public void testSetFacetValue() throws Exception {
-               FacetedSearchFacet testSubject;
-               String facetValue = "";
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setFacetValue(facetValue);
-       }
-
-       
-       @Test
-       public void testGetCount() throws Exception {
-               FacetedSearchFacet testSubject;
-               long result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getCount();
-       }
-
-       
        @Test
-       public void testSetCount() throws Exception {
-               FacetedSearchFacet testSubject;
-               long count = 555;
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setCount(count);
+       public void shouldHaveValidGettersAndSetters(){
+               assertThat(FacetedSearchFacet.class, hasValidGettersAndSetters());
        }
 }
\ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/model/FacetedSearchResult.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/model/FacetedSearchResult.java
new file mode 100644 (file)
index 0000000..b262dec
--- /dev/null
@@ -0,0 +1,13 @@
+package org.openecomp.sdc.be.dao.model;
+
+import org.junit.Test;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class FacetedSearchResult {
+       @Test
+       public void shouldHaveValidGettersAndSetters(){
+               assertThat(FacetedSearchResult.class, hasValidGettersAndSetters());
+       }
+}
\ No newline at end of file
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/model/FetchContext.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/model/FetchContext.java
new file mode 100644 (file)
index 0000000..c7ed9bc
--- /dev/null
@@ -0,0 +1,13 @@
+package org.openecomp.sdc.be.dao.model;
+
+import org.junit.Test;
+
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+public class FetchContext {
+       @Test
+       public void shouldHaveValidGettersAndSetters(){
+               assertThat(FetchContext.class, hasValidGettersAndSetters());
+       }
+}
\ No newline at end of file
index a330451..843e398 100644 (file)
 package org.openecomp.sdc.be.dao.model;
 
-import org.apache.tinkerpop.gremlin.structure.T;
 import org.junit.Test;
 
-public class GetMultipleDataResultTest {
-
-       private GetMultipleDataResult createTestSubject() {
-               return new GetMultipleDataResult<>();
-       }
+import static com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters;
+import static org.hamcrest.MatcherAssert.assertThat;
 
+public class GetMultipleDataResultTest {
+       
        @Test
        public void testCtor() throws Exception {
                new GetMultipleDataResult<>(new String [1], new Object[1]);
                new GetMultipleDataResult<>(new String [1], new String [1], 0L, 0L, 1, 1);
        }
-       
-       @Test
-       public void testGetTypes() throws Exception {
-               GetMultipleDataResult testSubject;
-               String[] result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getTypes();
-       }
-
-       @Test
-       public void testGetData() throws Exception {
-               GetMultipleDataResult testSubject;
-               Object[] result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getData();
-       }
-
-       @Test
-       public void testSetTypes() throws Exception {
-               GetMultipleDataResult testSubject;
-               String[] types = new String[] { "" };
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setTypes(types);
-       }
-
-       @Test
-       public void testSetData() throws Exception {
-               GetMultipleDataResult testSubject;
-               T[] data = new T[] { null };
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setData(data);
-       }
-
-       @Test
-       public void testSetQueryDuration() throws Exception {
-               GetMultipleDataResult testSubject;
-               long queryDuration = 0L;
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setQueryDuration(queryDuration);
-       }
-
+  
        @Test
-       public void testSetTotalResults() throws Exception {
-               GetMultipleDataResult testSubject;
-               long totalResults = 0L;
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setTotalResults(totalResults);
-       }
-
-       @Test
-       public void testSetFrom() throws Exception {
-               GetMultipleDataResult testSubject;
-               int from = 0;
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setFrom(from);
-       }
-
-       @Test
-       public void testSetTo() throws Exception {
-               GetMultipleDataResult testSubject;
-               int to = 0;
-
-               // default test
-               testSubject = createTestSubject();
-               testSubject.setTo(to);
-       }
-
-       @Test
-       public void testGetQueryDuration() throws Exception {
-               GetMultipleDataResult testSubject;
-               long result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getQueryDuration();
-       }
-
-       @Test
-       public void testGetTotalResults() throws Exception {
-               GetMultipleDataResult testSubject;
-               long result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getTotalResults();
-       }
-
-       @Test
-       public void testGetFrom() throws Exception {
-               GetMultipleDataResult testSubject;
-               int result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getFrom();
-       }
-
-       @Test
-       public void testGetTo() throws Exception {
-               GetMultipleDataResult testSubject;
-               int result;
-
-               // default test
-               testSubject = createTestSubject();
-               result = testSubject.getTo();
+       public void shouldHaveValidGettersAndSetters(){
+               assertThat(GetMultipleDataResultTest.class, hasValidGettersAndSetters());
        }
 }
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 0839407..fdbc5b5 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -90,6 +90,7 @@
         <testng.version>6.9.10</testng.version>
         <extentreports.version>3.0.3</extentreports.version>
         <cucumber.version>2.3.1</cucumber.version>
+        <bean-matchers.version>0.11</bean-matchers.version>
 
         <!-- parser-->
         <sdc-tosca-parser.version>1.2.3-SNAPSHOT</sdc-tosca-parser.version>