-
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.
* Make ReflectionUtils#getWriteMethod public * Move chained setters tests into a dedicated class
- Loading branch information
1 parent
e86984d
commit 305a1b5
Showing
5 changed files
with
119 additions
and
151 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
118 changes: 118 additions & 0 deletions
118
easy-random-core/src/test/java/org/jeasy/random/ChainedSettersSupportTest.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,118 @@ | ||
/* | ||
* 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 org.jeasy.random.beans.ChainedSetterBean; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class ChainedSettersSupportTest { | ||
|
||
@Test | ||
void generatedBeanWithFluentSetterShouldBeCorrectlyPopulated() { | ||
// given | ||
EasyRandom easyRandom = new EasyRandom(); | ||
|
||
// when | ||
ChainedSetterBean chainedSetterBean = easyRandom.nextObject(ChainedSetterBean.class); | ||
|
||
// then | ||
assertThat(chainedSetterBean.getName()).isNotEmpty(); | ||
assertThat(chainedSetterBean.getIndex()).isNotEqualTo(0); | ||
} | ||
|
||
@Test | ||
void chainSettersWithOverriddenFieldShouldBeRandomized() { | ||
// given | ||
class BaseClass { | ||
private String field; // field overridden (note: not setter) | ||
|
||
public BaseClass setField(String field) { | ||
this.field = field; | ||
return this; | ||
} | ||
} | ||
class SubClass extends BaseClass { | ||
private int field; // note: field overridden | ||
} | ||
EasyRandom easyRandom = new EasyRandom(); | ||
|
||
// when | ||
SubClass value = easyRandom.nextObject(SubClass.class); | ||
|
||
// then | ||
assertFalse(((BaseClass) value).field.isEmpty()); | ||
assertTrue(value.field != 0); | ||
} | ||
|
||
@Test | ||
void chainSettersWithOverriddenSetterShouldBeRandomized() { | ||
// given | ||
class BaseClass { | ||
private String field; // setter overridden | ||
private int f; // single-char name | ||
|
||
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; | ||
} | ||
} | ||
class SubClassB extends BaseClass { | ||
@Override | ||
public SubClassB setField(String field) { | ||
super.setField(field); | ||
return this; | ||
} | ||
} | ||
class SubClassA extends BaseClass { | ||
private SubClassB subClassB; | ||
} | ||
EasyRandom easyRandom = new EasyRandom(); | ||
|
||
// when | ||
SubClassA value = easyRandom.nextObject(SubClassA.class); | ||
|
||
// then | ||
assertNotNull(value.getField()); | ||
assertTrue(value.getF() != 0); | ||
} | ||
|
||
} |
82 changes: 0 additions & 82 deletions
82
easy-random-core/src/test/java/org/jeasy/random/EasyRandomChainedSettersTest.java
This file was deleted.
Oops, something went wrong.
59 changes: 0 additions & 59 deletions
59
easy-random-core/src/test/java/org/jeasy/random/EasyRandomOverridenFieldTest.java
This file was deleted.
Oops, something went wrong.
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