Skip to content

Commit 8c58a8f

Browse files
committed
Refactor of the Unit Test Example with TestNG Framework #6
Task-Url: http://github.com/tacianosilva/designtests/issues/issue/6
1 parent 4bd2a25 commit 8c58a8f

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
/jars/
44
/scripts/repos/
55
/.travis.yml~
6+
/test-output/

src/test/java/tests/br/edu/ufcg/splab/designtests/examples/testng/HibernateDesignTests.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public class HibernateDesignTests {
4141
@BeforeClass
4242
public void setUp() throws Exception {
4343
// Design for all classes in the project.
44-
dw = new DesignWizard("target/classes/");
44+
// Add here binary code or jar file of the project.
45+
dw = new DesignWizard("target/test-classes/");
4546
// Persistence classes of the model package of the project.
4647
entities = util.getClassesAnnotated(dw, "javax.persistence.Entity");
4748
}
@@ -60,26 +61,28 @@ public void tearDown() throws Exception {
6061
/**
6162
* The test verifies all entities if they follows the Rule:
6263
* Override both equals(java.lang.Object) and hashCode().
64+
* @see HashCodeAndEqualsRule
6365
*/
6466
public void testHashCodeAndEqualsRuleAll() {
6567
rule = new HashCodeAndEqualsRule(dw);
6668
rule.setClassNodes(entities);
67-
softAssert.assertTrue(rule.checkRule(), "\ncheckRule Failed");
68-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
69+
softAssert.assertTrue(rule.checkRule(), "\ncheckRule Failed: ");
70+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
6971

7072
softAssert.assertAll();
7173
}
7274

7375
/**
7476
* The test verifies each persistence entity if they follows the Rule:
7577
* Override both equals(java.lang.Object) and hashCode().
78+
* @see HashCodeAndEqualsRule
7679
*/
7780
public void testHashCodeAndEqualsRule() {
7881
rule = new HashCodeAndEqualsRule(dw);
7982
for (ClassNode entity : entities) {
8083
rule.setClassNode(entity);
81-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
82-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
84+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
85+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
8386
}
8487
softAssert.assertAll();
8588
}
@@ -94,8 +97,8 @@ public void testNoFinalClassRule() {
9497
rule = new NoFinalClassRule(dw);
9598
for (ClassNode entity : entities) {
9699
rule.setClassNode(entity);
97-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
98-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
100+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
101+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
99102
}
100103
softAssert.assertAll();
101104
}
@@ -111,8 +114,8 @@ public void testNoArgumentConstructorRule() {
111114
rule = new NoArgumentConstructorRule(dw);
112115
for (ClassNode entity : entities) {
113116
rule.setClassNode(entity);
114-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
115-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
117+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
118+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
116119
}
117120
softAssert.assertAll();
118121
}
@@ -126,8 +129,8 @@ public void testImplementsSerializableRule() {
126129
rule = new ImplementsSerializableRule(dw);
127130
for (ClassNode entity : entities) {
128131
rule.setClassNode(entity);
129-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
130-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
132+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
133+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
131134
}
132135
softAssert.assertAll();
133136
}
@@ -141,8 +144,8 @@ public void testProvideGetsSetsFieldsRule() {
141144
rule = new ProvideGetsSetsFieldsRule(dw);
142145
for (ClassNode entity : entities) {
143146
rule.setClassNode(entity);
144-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
145-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
147+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
148+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
146149
}
147150
softAssert.assertAll();
148151
}
@@ -156,8 +159,8 @@ public void testProvideIdentifierPropertyRule() {
156159
rule = new ProvideIdentifierPropertyRule(dw);
157160
for (ClassNode entity : entities) {
158161
rule.setClassNode(entity);
159-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
160-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
162+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
163+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
161164
}
162165
softAssert.assertAll();
163166
}
@@ -171,36 +174,38 @@ public void testUseInterfaceSetOrListRule() {
171174
rule = new UseInterfaceSetOrListRule(dw);
172175
for (ClassNode entity : entities) {
173176
rule.setClassNode(entity);
174-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
175-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
177+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
178+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
176179
}
177180
softAssert.assertAll();
178181
}
179182

180183
/**
181184
* The test verifies each persistence entity if they follows the Rule:
182185
* Declaration of Collection of the type List in classes of the Model Package.
186+
* @see UseListCollectionRule
183187
*/
184188
public void testUseListCollectionRule() {
185189
rule = new UseListCollectionRule(dw);
186190
for (ClassNode entity : entities) {
187191
rule.setClassNode(entity);
188-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
189-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
192+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
193+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
190194
}
191195
softAssert.assertAll();
192196
}
193197

194198
/**
195199
* The test verifies each persistence entity if they follows the Rule:
196200
* Declaration of Collection of the type Set in classes of the Model Package.
201+
* @see UseSetCollectionRule
197202
*/
198203
public void testUseSetCollectionRule() {
199204
rule = new UseSetCollectionRule(dw);
200205
for (ClassNode entity : entities) {
201206
rule.setClassNode(entity);
202-
softAssert.assertTrue(rule.checkRule(), "\nEntityFailed: " + entity.getShortName());
203-
softAssert.assertEquals("", rule.getReport(), "\nreport: \n" + rule.getReport());
207+
softAssert.assertTrue(rule.checkRule(), "\nEntity <" + entity.getShortName() + "> Failed: ");
208+
softAssert.assertEquals(rule.getReport(), "", "\nreport: ");
204209
}
205210
softAssert.assertAll();
206211
}

0 commit comments

Comments
 (0)