How to use StatementDescription method of org.evomaster.client.java.instrumentation.AdditionalInfo class

Best EvoMaster code snippet using org.evomaster.client.java.instrumentation.AdditionalInfo.StatementDescription

Source:AdditionalInfo.java Github

copy

Full Screen

...31 /**32 * Map from taint input name to string specializations for it33 */34 private Map<String, Set<StringSpecializationInfo>> stringSpecializations = new ConcurrentHashMap<>();35 private static class StatementDescription implements Serializable{36 public final String line;37 public final String method;38 public StatementDescription(String line, String method) {39 this.line = line;40 this.method = method;41 }42 }43 /**44 * Keep track of the last executed statement done in the SUT.45 * But not in the third-party libraries, just the business logic of the SUT.46 * The statement is represented with a descriptive unique id, like the class name and line number.47 *48 * We need to use a stack to handle method call invocations, as we can know when a statement49 * starts, but not so easily when it ends.50 */51 private Deque<StatementDescription> lastExecutedStatementStack = new ArrayDeque<>();52 /**53 * In case we pop all elements from stack, keep track of last one separately.54 */55 private StatementDescription noExceptionStatement = null;56 public void addSpecialization(String taintInputName, StringSpecializationInfo info){57 if(!ExecutionTracer.getTaintType(taintInputName).isTainted()){58 throw new IllegalArgumentException("No valid input name: " + taintInputName);59 }60 Objects.requireNonNull(info);61 stringSpecializations.putIfAbsent(taintInputName, new CopyOnWriteArraySet<>());62 Set<StringSpecializationInfo> set = stringSpecializations.get(taintInputName);63 set.add(info);64 }65 public Map<String, Set<StringSpecializationInfo>> getStringSpecializationsView(){66 //note: this does not prevent modifying the sets inside it67 return Collections.unmodifiableMap(stringSpecializations);68 }69 public void addQueryParameter(String param){70 if(param != null && ! param.isEmpty()){71 queryParameters.add(param);72 }73 }74 public Set<String> getQueryParametersView(){75 return Collections.unmodifiableSet(queryParameters);76 }77 public void addHeader(String header){78 if(header != null && ! header.isEmpty()){79 headers.add(header);80 }81 }82 public Set<String> getHeadersView(){83 return Collections.unmodifiableSet(headers);84 }85 public String getLastExecutedStatement() {86 if(lastExecutedStatementStack.isEmpty()){87 if(noExceptionStatement == null){88 return null;89 }90 return noExceptionStatement.line;91 }92 StatementDescription current = lastExecutedStatementStack.peek();93 return current.line;94 }95 public void pushLastExecutedStatement(String lastLine, String lastMethod) {96 noExceptionStatement = null;97 StatementDescription statement = new StatementDescription(lastLine, lastMethod);98 StatementDescription current = lastExecutedStatementStack.peek();99 //if some method, then replace top of stack100 if(current != null && lastMethod.equals(current.method)){101 lastExecutedStatementStack.pop();102 }103 lastExecutedStatementStack.push(statement);104 }105 public void popLastExecutedStatement(){106 StatementDescription statementDescription = lastExecutedStatementStack.pop();107 if(lastExecutedStatementStack.isEmpty()){108 noExceptionStatement = statementDescription;109 }110 }111}...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful