-
Notifications
You must be signed in to change notification settings - Fork 234
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
203 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
easy-random-core/src/test/java/org/jeasy/random/EasyRandomChainedSettersTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2020, Mahmoud Ben Hassine ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.jeasy.random; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class EasyRandomChainedSettersTest { | ||
|
||
@Test | ||
void chainSettersShouldBeRandomized() { | ||
EasyRandom easyRandom = new EasyRandom(new EasyRandomParameters()); | ||
|
||
SubClassA value = easyRandom.nextObject(SubClassA.class); | ||
|
||
assertNotNull(value.getField()); | ||
assertTrue(value.getF() != 0); | ||
} | ||
|
||
public static class BaseClass { | ||
|
||
// setter overriden | ||
private String field; | ||
// single-char name | ||
private int f; | ||
|
||
public BaseClass setField(String field) { | ||
this.field = field; | ||
return this; | ||
} | ||
|
||
public String getField() { | ||
return field; | ||
} | ||
|
||
public int getF() { | ||
return f; | ||
} | ||
|
||
public BaseClass setF(int f) { | ||
this.f = f; | ||
return this; | ||
} | ||
} | ||
|
||
public static class SubClassA extends BaseClass { | ||
|
||
private SubClassB subClassB; | ||
} | ||
|
||
public static class SubClassB extends BaseClass { | ||
|
||
@Override | ||
public SubClassB setField(String field) { | ||
super.setField(field); | ||
return this; | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
easy-random-core/src/test/java/org/jeasy/random/EasyRandomOverridenFieldTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2020, Mahmoud Ben Hassine ([email protected]) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package org.jeasy.random; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class EasyRandomOverridenFieldTest { | ||
|
||
@Test | ||
void chainSettersShouldBeRandomized() { | ||
EasyRandom easyRandom = new EasyRandom(new EasyRandomParameters()); | ||
|
||
SubClass value = easyRandom.nextObject(SubClass.class); | ||
|
||
assertFalse(((BaseClass) value).field.isEmpty()); | ||
assertTrue(value.field != 0); | ||
} | ||
|
||
public static class BaseClass { | ||
|
||
// field overriden (note: not setter) | ||
private String field; | ||
|
||
public BaseClass setField(String field) { | ||
this.field = field; | ||
return this; | ||
} | ||
} | ||
|
||
public static class SubClass extends BaseClass { | ||
|
||
// note: field overriden | ||
private int field; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters