Skip to content

Commit d4da59e

Browse files
committed
HBX-2789: Review WrapperFactory class and create only new Wrapper intances
- Change the returned class of the methods of interface 'org.hibernate.tool.orm.jbt.api.wrp.RevengSettingsWrapper' to return in instance of 'org.hibernate.tool.orm.jbt.api.wrp.RevengSettingsWrapper' - Adapt implementation class 'org.hibernate.tool.orm.jbt.internal.factory.RevengSettingsWrapperFactory.RevengSettingsWrapperImpl' accordingly - Add an additional assertion to verify the above in the test methods of test class 'org.hibernate.tool.orm.jbt.internal.factory.RevengSettingsWrapperFactoryTest' Signed-off-by: Koen Aers <[email protected]>
1 parent 7d95119 commit d4da59e

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

jbt/src/main/java/org/hibernate/tool/orm/jbt/api/wrp/RevengSettingsWrapper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
public interface RevengSettingsWrapper extends Wrapper {
44

5-
void setDefaultPackageName(String s);
6-
void setDetectManyToMany(boolean b);
7-
void setDetectOneToOne(boolean b);
8-
void setDetectOptimisticLock(boolean b);
5+
RevengSettingsWrapper setDefaultPackageName(String s);
6+
RevengSettingsWrapper setDetectManyToMany(boolean b);
7+
RevengSettingsWrapper setDetectOneToOne(boolean b);
8+
RevengSettingsWrapper setDetectOptimisticLock(boolean b);
99

1010
}

jbt/src/main/java/org/hibernate/tool/orm/jbt/internal/factory/RevengSettingsWrapperFactory.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,27 @@ public RevengSettings getWrappedObject() {
3333
}
3434

3535
@Override
36-
public void setDefaultPackageName(String s) {
36+
public RevengSettingsWrapper setDefaultPackageName(String s) {
3737
revengSettings.setDefaultPackageName(s);
38+
return this;
3839
}
3940

4041
@Override
41-
public void setDetectManyToMany(boolean b) {
42+
public RevengSettingsWrapper setDetectManyToMany(boolean b) {
4243
revengSettings.setDetectManyToMany(b);
44+
return this;
4345
}
4446

4547
@Override
46-
public void setDetectOneToOne(boolean b) {
48+
public RevengSettingsWrapper setDetectOneToOne(boolean b) {
4749
revengSettings.setDetectOneToOne(b);
50+
return this;
4851
}
4952

5053
@Override
51-
public void setDetectOptimisticLock(boolean b) {
54+
public RevengSettingsWrapper setDetectOptimisticLock(boolean b) {
5255
revengSettings.setDetectOptimisticLock(b);
56+
return this;
5357
}
5458

5559
}

jbt/src/test/java/org/hibernate/tool/orm/jbt/api/wrp/RevengSettingsWrapperTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertFalse;
55
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertSame;
67
import static org.junit.jupiter.api.Assertions.assertTrue;
78

89
import org.hibernate.tool.api.reveng.RevengSettings;
@@ -31,28 +32,28 @@ public void testConstruction() {
3132
@Test
3233
public void testSetDefaultPackageName() {
3334
assertEquals("", wrappedRevengSettings.getDefaultPackageName());
34-
revengSettingsWrapper.setDefaultPackageName("foo");
35+
assertSame(revengSettingsWrapper, revengSettingsWrapper.setDefaultPackageName("foo"));
3536
assertEquals("foo", wrappedRevengSettings.getDefaultPackageName());
3637
}
3738

3839
@Test
3940
public void testSetDetectManyToMany() {
4041
assertTrue(wrappedRevengSettings.getDetectManyToMany());
41-
revengSettingsWrapper.setDetectManyToMany(false);
42+
assertSame(revengSettingsWrapper, revengSettingsWrapper.setDetectManyToMany(false));
4243
assertFalse(wrappedRevengSettings.getDetectManyToMany());
4344
}
4445

4546
@Test
4647
public void testSetDetectOneToOne() {
4748
assertTrue(wrappedRevengSettings.getDetectOneToOne());
48-
revengSettingsWrapper.setDetectOneToOne(false);
49+
assertSame(revengSettingsWrapper, revengSettingsWrapper.setDetectOneToOne(false));
4950
assertFalse(wrappedRevengSettings.getDetectOneToOne());
5051
}
5152

5253
@Test
5354
public void testSetDetectOptimisticLock() {
5455
assertTrue(wrappedRevengSettings.getDetectOptimsticLock());
55-
revengSettingsWrapper.setDetectOptimisticLock(false);
56+
assertSame(revengSettingsWrapper, revengSettingsWrapper.setDetectOptimisticLock(false));
5657
assertFalse(wrappedRevengSettings.getDetectOptimsticLock());
5758
}
5859

0 commit comments

Comments
 (0)