mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-10 17:49:38 +02:00
Add more checkstyle tests
- Lines containing tab(s) after space - Usage of printStackTrace - Usage of println - Add SupressionCommentFilter module SuppressionCommentFilter can be enabled with // CHECKSTYLE:OFF and disabled with // CHECKSTYLE:ON
This commit is contained in:
parent
4f64bb1036
commit
b2221d5483
59 changed files with 382 additions and 202 deletions
|
@ -244,10 +244,12 @@ public class PacketCollector {
|
|||
*/
|
||||
protected void processPacket(Stanza packet) {
|
||||
if (packetFilter == null || packetFilter.accept(packet)) {
|
||||
// CHECKSTYLE:OFF
|
||||
while (!resultQueue.offer(packet)) {
|
||||
// Since we know the queue is full, this poll should never actually block.
|
||||
resultQueue.poll();
|
||||
}
|
||||
// CHECKSTYLE:ON
|
||||
if (collectorToReset != null) {
|
||||
collectorToReset.waitStart = System.currentTimeMillis();
|
||||
}
|
||||
|
|
|
@ -98,15 +98,13 @@ public abstract class AbstractDebugger implements SmackDebugger {
|
|||
log(
|
||||
"XMPPConnection closed due to an exception (" +
|
||||
connection.getConnectionCounter() +
|
||||
")");
|
||||
e.printStackTrace();
|
||||
")", e);
|
||||
}
|
||||
public void reconnectionFailed(Exception e) {
|
||||
log(
|
||||
"Reconnection failed due to an exception (" +
|
||||
connection.getConnectionCounter() +
|
||||
")");
|
||||
e.printStackTrace();
|
||||
")", e);
|
||||
}
|
||||
public void reconnectionSuccessful() {
|
||||
log(
|
||||
|
@ -125,6 +123,8 @@ public abstract class AbstractDebugger implements SmackDebugger {
|
|||
|
||||
protected abstract void log(String logMessage);
|
||||
|
||||
protected abstract void log(String logMessage, Throwable throwable);
|
||||
|
||||
public Reader newConnectionReader(Reader newReader) {
|
||||
reader.removeReaderListener(readerListener);
|
||||
ObservableReader debugReader = new ObservableReader(newReader);
|
||||
|
|
|
@ -18,7 +18,9 @@ package org.jivesoftware.smack.debugger;
|
|||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
@ -47,7 +49,19 @@ public class ConsoleDebugger extends AbstractDebugger {
|
|||
synchronized (dateFormatter) {
|
||||
formatedDate = dateFormatter.format(new Date());
|
||||
}
|
||||
// CHECKSTYLE:OFF
|
||||
System.out.println(formatedDate + ' ' + logMessage);
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void log(String logMessage, Throwable throwable) {
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
// CHECKSTYLE:OFF
|
||||
throwable.printStackTrace(pw);
|
||||
// CHECKSTYLE:ON
|
||||
log(logMessage + sw);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.jivesoftware.smack.XMPPConnection;
|
|||
|
||||
import java.io.Reader;
|
||||
import java.io.Writer;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
|
@ -46,4 +47,8 @@ public class JulDebugger extends AbstractDebugger {
|
|||
LOGGER.fine(logMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void log(String logMessage, Throwable throwable) {
|
||||
LOGGER.log(Level.FINE, logMessage, throwable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -528,7 +528,9 @@ public class PacketParserUtils {
|
|||
|
||||
String language = getLanguageAttribute(parser);
|
||||
if (language != null && !"".equals(language.trim())) {
|
||||
// CHECKSTYLE:OFF
|
||||
presence.setLanguage(language);
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
// Parse sub-elements
|
||||
|
@ -993,15 +995,19 @@ public class PacketParserUtils {
|
|||
|
||||
}
|
||||
private static String getLanguageAttribute(XmlPullParser parser) {
|
||||
// CHECKSTYLE:OFF
|
||||
for (int i = 0; i < parser.getAttributeCount(); i++) {
|
||||
// CHECKSTYLE:ON
|
||||
String attributeName = parser.getAttributeName(i);
|
||||
if ( "xml:lang".equals(attributeName) ||
|
||||
("lang".equals(attributeName) &&
|
||||
"xml".equals(parser.getAttributePrefix(i)))) {
|
||||
// CHECKSTYLE:OFF
|
||||
return parser.getAttributeValue(i);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
|
|
|
@ -134,17 +134,11 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
|
||||
@Override
|
||||
public void send(PlainStreamElement element) {
|
||||
if (SmackConfiguration.DEBUG) {
|
||||
System.out.println("[SEND]: " + element.toXML());
|
||||
}
|
||||
queue.add(element);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void sendStanzaInternal(Stanza packet) {
|
||||
if (SmackConfiguration.DEBUG) {
|
||||
System.out.println("[SEND]: " + packet.toXML());
|
||||
}
|
||||
queue.add(packet);
|
||||
}
|
||||
|
||||
|
@ -194,10 +188,6 @@ public class DummyConnection extends AbstractXMPPConnection {
|
|||
* @param packet the packet to process.
|
||||
*/
|
||||
public void processPacket(Stanza packet) {
|
||||
if (SmackConfiguration.DEBUG) {
|
||||
System.out.println("[RECV]: " + packet.toXML());
|
||||
}
|
||||
|
||||
invokePacketCollectorsAndNotifyRecvListeners(packet);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ import java.io.IOException;
|
|||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||
import org.jivesoftware.smack.packet.IQ;
|
||||
|
@ -33,6 +35,8 @@ import org.jivesoftware.smack.packet.IQ.Type;
|
|||
*
|
||||
*/
|
||||
public class ThreadedDummyConnection extends DummyConnection {
|
||||
private static final Logger LOGGER = Logger.getLogger(ThreadedDummyConnection.class.getName());
|
||||
|
||||
private BlockingQueue<IQ> replyQ = new ArrayBlockingQueue<IQ>(1);
|
||||
private BlockingQueue<Stanza> messageQ = new LinkedBlockingQueue<Stanza>(5);
|
||||
private volatile boolean timeout = false;
|
||||
|
@ -82,7 +86,7 @@ public class ThreadedDummyConnection extends DummyConnection {
|
|||
if (!messageQ.isEmpty())
|
||||
new ProcessQueue(messageQ).start();
|
||||
else
|
||||
System.out.println("No messages to process");
|
||||
LOGGER.warning("No messages to process");
|
||||
}
|
||||
|
||||
class ProcessQueue extends Thread {
|
||||
|
@ -97,7 +101,7 @@ public class ThreadedDummyConnection extends DummyConnection {
|
|||
try {
|
||||
processPacket(processQ.take());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.log(Level.WARNING, "exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -754,25 +754,30 @@ public class PacketParserUtilsTest {
|
|||
|
||||
@Test
|
||||
public void validateSimplePresence() throws Exception {
|
||||
// CHECKSTYLE:OFF
|
||||
String stanza = "<presence from='juliet@example.com/balcony' to='romeo@example.net'/>";
|
||||
|
||||
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
|
||||
|
||||
assertXMLEqual(stanza, presence.toXML().toString());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validatePresenceProbe() throws Exception {
|
||||
// CHECKSTYLE:OFF
|
||||
String stanza = "<presence from='mercutio@example.com' id='xv291f38' to='juliet@example.com' type='unsubscribed'/>";
|
||||
|
||||
Presence presence = PacketParserUtils.parsePresence(PacketParserUtils.getParserFor(stanza));
|
||||
|
||||
assertXMLEqual(stanza, presence.toXML().toString());
|
||||
assertEquals(Presence.Type.unsubscribed, presence.getType());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validatePresenceOptionalElements() throws Exception {
|
||||
// CHECKSTYLE:OFF
|
||||
String stanza = "<presence xml:lang='en' type='unsubscribed'>"
|
||||
+ "<show>dnd</show>"
|
||||
+ "<status>Wooing Juliet</status>"
|
||||
|
@ -786,6 +791,7 @@ public class PacketParserUtilsTest {
|
|||
assertEquals("en", presence.getLanguage());
|
||||
assertEquals("Wooing Juliet", presence.getStatus());
|
||||
assertEquals(1, presence.getPriority());
|
||||
// CHECKSTYLE:ON
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue