diff --git a/smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java b/smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java index 3be7080b7e..82ca10b62f 100644 --- a/smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java +++ b/smack-core/src/main/java/org/jivesoftware/smack/debugger/SmackDebugger.java @@ -1,6 +1,6 @@ /** * - * Copyright 2003-2007 Jive Software, 2017 Florian Schmaus, 2024 Guus der Kinderen + * Copyright 2003-2007 Jive Software, 2017 Florian Schmaus. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +20,6 @@ import java.io.IOException; import java.io.Reader; import java.io.Writer; -import java.util.HashMap; -import java.util.Map; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.packet.TopLevelStreamElement; @@ -43,8 +41,6 @@ */ public abstract class SmackDebugger { - private static final Map CONTEXT = new HashMap<>(); - protected final XMPPConnection connection; private XmppXmlSplitter outgoingStreamSplitterForPrettyPrinting; @@ -153,46 +149,4 @@ public final Writer newConnectionWriter(Writer writer) { */ public abstract void onOutgoingStreamElement(TopLevelStreamElement streamElement); - /** - * Associates the specified value with the specified key in the debugging context, following the contract as - * specified by {@link Map#put(Object, Object)}. - * - * @param key key with which the specified value is to be associated - * @param value value to be associated with the specified key - * @return the previous value associated with key, or null if there was no mapping for key. A null return can - * also indicate that the map previously associated null with key. - */ - public static String putInContext(final String key, final String value) { - return CONTEXT.put(key, value); - } - - /** - * Returns the value to which the specified key is mapped, or null if the debugging context contains no mapping for - * the key, following the contract as specified by {@link Map#get(Object)}. - * - * @param key the key whose associated value is to be returned - * @return the value to which the specified key is mapped, or null if this map contains no mapping for the key - */ - public static String getFromContext(final String key) { - return CONTEXT.get(key); - } - - /** - * Removes the mapping for a key from the debugging context if it is present, following the contract as - * specified by {@link Map#remove(Object)}. - * - * @param key the key whose associated value is to be returned - * @return the value to which the specified key is mapped, or null if this map contains no mapping for the key - */ - public static String removeFromContext(final String key) { - return CONTEXT.remove(key); - } - - /** - * Removes all of the mappings from the debugging context. The debugging context will be empty after this call - * returns. - */ - public static void clearContext() { - CONTEXT.clear(); - } } diff --git a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java index aad1d26d15..436a67c47d 100644 --- a/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java +++ b/smack-integration-test/src/main/java/org/igniterealtime/smack/inttest/SmackIntegrationTestFramework.java @@ -57,7 +57,6 @@ import org.jivesoftware.smack.SmackException.NotConnectedException; import org.jivesoftware.smack.XMPPException; import org.jivesoftware.smack.XMPPException.XMPPErrorException; -import org.jivesoftware.smack.debugger.SmackDebugger; import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration; import org.jivesoftware.smack.util.StringUtils; import org.jivesoftware.smack.util.TLSUtils; @@ -88,6 +87,8 @@ public class SmackIntegrationTestFramework { public static boolean SINTTEST_UNIT_TEST = false; + private static ConcreteTest TEST_UNDER_EXECUTION; + protected final Configuration config; protected TestRunResult testRunResult; @@ -245,6 +246,10 @@ public synchronized TestRunResult run() return testRunResult; } + public static ConcreteTest getTestUnderExecution() { + return TEST_UNDER_EXECUTION; + } + @SuppressWarnings({"Finally"}) private void runTests(Set> classes) throws InterruptedException, InstantiationException, IllegalAccessException, @@ -677,19 +682,20 @@ private PreparedTest(AbstractSmackIntTest test, List concreteTests public void run() throws InterruptedException, XMPPException, IOException, SmackException { try { - SmackDebugger.putInContext("sint.test", test.getClass().getSimpleName()); - // Run the @BeforeClass methods (if any) executeSinttestSpecialMethod(beforeClassMethod); for (ConcreteTest concreteTest : concreteTests) { - SmackDebugger.putInContext("sint.concreteTest", concreteTest.toString()); - runConcreteTest(concreteTest); + try { + TEST_UNDER_EXECUTION = concreteTest; + runConcreteTest(concreteTest); + } finally { + TEST_UNDER_EXECUTION = null; + } } } finally { executeSinttestSpecialMethod(afterClassMethod); - SmackDebugger.clearContext(); } } @@ -734,21 +740,37 @@ else if (specialClassMethods.size() > 1) { return null; } - static final class ConcreteTest { + public static final class ConcreteTest { private final TestType testType; private final Method method; private final Executor executor; - private final String[] subdescriptons; + private final List subdescriptons; private ConcreteTest(TestType testType, Method method, Executor executor, String... subdescriptions) { this.testType = testType; this.method = method; this.executor = executor; - this.subdescriptons = subdescriptions; + if (subdescriptions == null) { + this.subdescriptons = null; + } else { + this.subdescriptons = List.of(subdescriptions); + } } private transient String stringCache; + public TestType getTestType() { + return testType; + } + + public Method getMethod() { + return method; + } + + public List getSubdescriptons() { + return subdescriptons; + } + @Override public String toString() { if (stringCache != null) { @@ -761,9 +783,9 @@ public String toString() { .append(method.getName()) .append(" (") .append(testType.name()); - if (subdescriptons != null && subdescriptons.length > 0) { + if (subdescriptons != null && !subdescriptons.isEmpty()) { sb.append(", "); - StringUtils.appendTo(Arrays.asList(subdescriptons), sb); + StringUtils.appendTo(subdescriptons, sb); } sb.append(')');