Skip to content

Commit

Permalink
Merge 99327d6 into e504bc2
Browse files Browse the repository at this point in the history
  • Loading branch information
guusdk committed Mar 21, 2024
2 parents e504bc2 + 99327d6 commit a60d24e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
*
* Copyright 2003-2007 Jive Software, 2017 Florian Schmaus.
* Copyright 2003-2007 Jive Software, 2017 Florian Schmaus, 2024 Guus der Kinderen
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,8 @@
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;
Expand All @@ -41,6 +43,8 @@
*/
public abstract class SmackDebugger {

private static final Map<String, String> CONTEXT = new HashMap<>();

protected final XMPPConnection connection;

private XmppXmlSplitter outgoingStreamSplitterForPrettyPrinting;
Expand Down Expand Up @@ -149,4 +153,46 @@ 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
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;
Expand Down Expand Up @@ -676,15 +677,19 @@ private PreparedTest(AbstractSmackIntTest test, List<ConcreteTest> 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);
}
}
finally {
executeSinttestSpecialMethod(afterClassMethod);
SmackDebugger.clearContext();
}
}

Expand Down

0 comments on commit a60d24e

Please sign in to comment.