Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nullable types to random provider type generator #62

Merged

Conversation

andrew-kirkham
Copy link
Contributor

@andrew-kirkham andrew-kirkham commented Mar 9, 2021

adds the ability to create nullable explicitly set to null via the random type generator via nullableTypeGenerator

this also allows you to set one for typeGenerator<T> and another for nullableTypeGenerator<T?> if you wanted separate values but if you specify typeGenerator<T> and not nullableTypeGenerator<T?> then it will default to the not-null value for any <T>
so:

class Foo(val int: Int?)

randomProvider.randomClassInstance<Foo> {
	typeGenerator<Int> { 3 }
}.int == 3

randomProvider.randomClassInstance<Foo>{
	nullableTypeGenerator<Int?> { 3 } 
}.int == 3

randomProvider.randomClassInstance<Foo>{
	nullableTypeGenerator<Int?> { null } 
}.int == null

randomProvider.randomClassInstance<Foo>{
	  typeGenerator<Int> { 3 } 	
	  nullableTypeGenerator<Int?> { null } 
}.int == null

@serpro69
Copy link
Owner

Hi @andrew-kirkham and thanks for the PR!
I'll take a look at it once I have some free time off work.

Copy link
Owner

@serpro69 serpro69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks fine to me, just one small comment about renaming the function.

@serpro69 serpro69 changed the title add nullable types to random provider type generator Add nullable types to random provider type generator Mar 12, 2021
@andrew-kirkham andrew-kirkham requested a review from serpro69 March 12, 2021 19:22
Copy link
Owner

@serpro69 serpro69 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks

@serpro69 serpro69 merged commit b929fee into serpro69:master Mar 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants