How can I generate a String of a given size?
int someLimit = GlobalLimits.BULK_SIZE;
I want 3 Strings which satisfy the below conditions.
- RandomStr.length < someLimit.length
- RandomStr.length = someLimit.length
- RandomStr.length > someLimit.length
This is what I have tried so far.
private String getLowerRandomString(int upto){
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < upto; i++){
sBuilder.append("A");
}
return sBuilder.toString();
}
The problem what I see is, if my limit = 10000, it still loop up-to 9999 which is unnecessary. Share if you know a better approach than this. Thank you.
FYI: I was writing a unit test for a simple helper method.
public boolean isBulk(String text){
int bulkLimit = ImportToolkit.getSizeLimit();
if (text != null && text.length() > bulkLimit){
return true;
}
return false;
}
So, I want to pass different sizes of strings as parameters to this method and want to assert whether it gives me expected results.
Aucun commentaire:
Enregistrer un commentaire