### Question:
ServletTransactionHelper { public static void setTransactionNameByServletClass(@Nullable String method, @Nullable Class<?> servletClass, Transaction transaction) { if (servletClass == null) { return; } StringBuilder transactionName = transaction.getAndOverrideName(PRIO_LOW_LEVEL_FRAMEWORK); if (transactionName == null) { return; } String servletClassName = servletClass.getName(); transactionName.append(servletClassName, servletClassName.lastIndexOf('.') + 1, servletClassName.length()); if (method != null) { transactionName.append('#'); switch (method) { case "DELETE": transactionName.append("doDelete"); break; case "HEAD": transactionName.append("doHead"); break; case "GET": transactionName.append("doGet"); break; case "OPTIONS": transactionName.append("doOptions"); break; case "POST": transactionName.append("doPost"); break; case "PUT": transactionName.append("doPut"); break; case "TRACE": transactionName.append("doTrace"); break; default: transactionName.append(method); } } } ServletTransactionHelper(ElasticApmTracer tracer); static void determineServiceName(@Nullable String servletContextName, @Nullable ClassLoader servletContextClassLoader, @Nullable String contextPath); void fillRequestContext(Transaction transaction, String protocol, String method, boolean secure,
                                   String scheme, String serverName, int serverPort, String requestURI, String queryString,
                                   String remoteAddr, @Nullable String contentTypeHeader); static void setUsernameIfUnset(@Nullable String userName, TransactionContext context); void onAfter(Transaction transaction, @Nullable Throwable exception, boolean committed, int status,
                        boolean overrideStatusCodeOnThrowable, String method, @Nullable Map<String, String[]> parameterMap,
                        @Nullable String servletPath, @Nullable String pathInfo, @Nullable String contentTypeHeader, boolean deactivate); boolean captureParameters(String method, @Nullable String contentTypeHeader); static void setTransactionNameByServletClass(@Nullable String method, @Nullable Class<?> servletClass, Transaction transaction); boolean isCaptureHeaders(); static final String TRANSACTION_ATTRIBUTE; static final String ASYNC_ATTRIBUTE; }### Answer:
@Test void setTransactionNameByServletClass() { Transaction transaction = new Transaction(MockTracer.create()); ServletTransactionHelper.setTransactionNameByServletClass("GET", ServletTransactionHelperTest.class, transaction); assertThat(transaction.getNameAsString()).isEqualTo("ServletTransactionHelperTest#doGet"); }
@Test void setTransactionNameByServletClassNullMethod() { Transaction transaction = new Transaction(MockTracer.create()); ServletTransactionHelper.setTransactionNameByServletClass(null, ServletTransactionHelperTest.class, transaction); assertThat(transaction.getNameAsString()).isEqualTo("ServletTransactionHelperTest"); }