I'm using the follow code to generate random e-mails on the dataMap class:
public static String generateRandomEmail(int length) {
String allowedChars = "abcdefghijklmnopqrstuvwxyz" + "_-.";
String email = "";
String temp = RandomStringUtils.random(length, allowedChars);
email = temp.substring(0, temp.length() - 1)+"@mailinator.com";
System.out.println(email);
return email;
}
On my steps class, I need to use this email value, but I'm calling the method again, so it's generate another "email".
@Dado("que realizo a chamada no (.*) da (.*) informando (.*) e um email e (.*) novos")
public void verificarAmbiente(String srtAmbiente, String srtAPI, String srtToken, String srtSenha) {
System.out.println(srtAmbiente+srtAPI);
dataMap data = new dataMap();
int length = 15;
data.generateRandomEmail(length);
Map<String, String> emailContent = new HashMap<String,String>();
emailContent.put("email", data.generateRandomEmail(length));
Map<String, Object> postContent = new HashMap<String,Object>();
postContent.put("customer", emailContent);
postContent.put("password", srtSenha);
given().contentType(ContentType.JSON)
.header("Authorization", "Bearer "+srtToken)
.with().body(postContent)
.when().post(srtAmbiente+srtAPI).prettyPeek()
.then().statusCode(200);
}
I wanna transform the "return email" in a variable and call it in another class without execute the method again and change the value. Can you help me? Thanks!
data.generateRandomEmail(length);doString email = data.generateRandomEmail(length);and then useemailthe second time around.generateRandomEmailis not needed at all, as it doesn't change any state. It just generates the email, returns it, but the return value is thrown away