1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-10 18:59:41 +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:
Florian Schmaus 2015-03-17 21:19:06 +01:00
parent 4f64bb1036
commit b2221d5483
59 changed files with 382 additions and 202 deletions

View file

@ -93,11 +93,15 @@ public class Privacy extends IQ {
*/
public void deletePrivacyList(String listName) {
// Remove the list from the cache
// CHECKSTYLE:OFF
this.getItemLists().remove(listName);
// CHECKSTYLE:ON
// Check if deleted list was the default list
if (this.getDefaultName() != null && listName.equals(this.getDefaultName())) {
// CHECKSTYLE:OFF
this.setDefaultName(null);
// CHECKSTYLE:ON
}
}
@ -108,11 +112,13 @@ public class Privacy extends IQ {
*/
public List<PrivacyItem> getActivePrivacyList() {
// Check if we have the default list
// CHECKSTYLE:OFF
if (this.getActiveName() == null) {
return null;
} else {
return this.getItemLists().get(this.getActiveName());
}
// CHECKSTYLE:ON
}
/**
@ -122,11 +128,13 @@ public class Privacy extends IQ {
*/
public List<PrivacyItem> getDefaultPrivacyList() {
// Check if we have the default list
// CHECKSTYLE:OFF
if (this.getDefaultName() == null) {
return null;
} else {
return this.getItemLists().get(this.getDefaultName());
}
// CHECKSTYLE:ON
}
/**
@ -147,6 +155,7 @@ public class Privacy extends IQ {
* @return a List with {@link PrivacyItem}
*/
public PrivacyItem getItem(String listName, int order) {
// CHECKSTYLE:OFF
Iterator<PrivacyItem> values = getPrivacyList(listName).iterator();
PrivacyItem itemFound = null;
while (itemFound == null && values.hasNext()) {
@ -156,6 +165,7 @@ public class Privacy extends IQ {
}
}
return itemFound;
// CHECKSTYLE:ON
}
/**
@ -169,7 +179,9 @@ public class Privacy extends IQ {
this.setDefaultName(newDefault);
return true;
} else {
// CHECKSTYLE:OFF
return false;
// CHECKSTYLE:ON
}
}
@ -179,7 +191,9 @@ public class Privacy extends IQ {
* @param listName name of the list to remove.
*/
public void deleteList(String listName) {
// CHECKSTYLE:OFF
this.getItemLists().remove(listName);
// CHECKSTYLE:ON
}
/**
@ -188,9 +202,11 @@ public class Privacy extends IQ {
*
* @return the name of the active list.
*/
// CHECKSTYLE:OFF
public String getActiveName() {
return activeName;
}
// CHECKSTYLE:ON
/**
* Sets the name associated with the active list set for the session. Communications
@ -198,9 +214,11 @@ public class Privacy extends IQ {
*
* @param activeName is the name of the active list.
*/
// CHECKSTYLE:OFF
public void setActiveName(String activeName) {
this.activeName = activeName;
}
// CHECKSTYLE:ON
/**
* Returns the name of the default list that applies to the user as a whole. Default list is
@ -209,9 +227,11 @@ public class Privacy extends IQ {
*
* @return the name of the default list.
*/
// CHECKSTYLE:OFF
public String getDefaultName() {
return defaultName;
}
// CHECKSTYLE:ON
/**
* Sets the name of the default list that applies to the user as a whole. Default list is
@ -222,9 +242,11 @@ public class Privacy extends IQ {
*
* @param defaultName is the name of the default list.
*/
// CHECKSTYLE:OFF
public void setDefaultName(String defaultName) {
this.defaultName = defaultName;
}
// CHECKSTYLE:ON
/**
* Returns the collection of privacy list that the user holds. A Privacy List contains a set of
@ -234,42 +256,51 @@ public class Privacy extends IQ {
* @return a map where the key is the name of the list and the value the
* collection of privacy items.
*/
// CHECKSTYLE:OFF
public Map<String, List<PrivacyItem>> getItemLists() {
return itemLists;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or declines the use of an active list.
*
* @return the decline status of the list.
*/
// CHECKSTYLE:OFF
public boolean isDeclineActiveList() {
return declineActiveList;
}
// CHECKSYTLE:ON
/**
* Sets whether the receiver allows or declines the use of an active list.
*
* @param declineActiveList indicates if the receiver declines the use of an active list.
*/
// CHECKSTYLE:OFF
public void setDeclineActiveList(boolean declineActiveList) {
this.declineActiveList = declineActiveList;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or declines the use of a default list.
*
* @return the decline status of the list.
*/
// CHECKSTYLE:OFF
public boolean isDeclineDefaultList() {
return declineDefaultList;
}
// CHECKSTYLE:ON
/**
* Sets whether the receiver allows or declines the use of a default list.
*
* @param declineDefaultList indicates if the receiver declines the use of a default list.
*/
// CHECKSTYLE:OFF
public void setDeclineDefaultList(boolean declineDefaultList) {
this.declineDefaultList = declineDefaultList;
}
@ -282,10 +313,12 @@ public class Privacy extends IQ {
public Set<String> getPrivacyListNames() {
return this.itemLists.keySet();
}
// CHECKSTYLE:ON
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
buf.rightAngleBracket();
// CHECKSTYLE:OFF
// Add the active tag
if (this.isDeclineActiveList()) {
@ -323,7 +356,7 @@ public class Privacy extends IQ {
buf.append("</list>");
}
}
// CHECKSTYLE:ON
return buf;
}

View file

@ -131,8 +131,10 @@ public class PrivacyItem {
* @return the allow communication status.
*/
public boolean isAllow() {
// CHECKSTYLE:OFF
return allow;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allow or deny incoming IQ stanzas or not.
@ -140,8 +142,10 @@ public class PrivacyItem {
* @return the iq filtering status.
*/
public boolean isFilterIQ() {
// CHECKSTYLE:OFF
return filterIQ;
}
// CHECKSTYLE:ON
/**
* Sets whether the receiver allows or denies incoming IQ stanzas or not.
@ -149,8 +153,11 @@ public class PrivacyItem {
* @param filterIQ indicates if the receiver allows or denies incoming IQ stanzas.
*/
public void setFilterIQ(boolean filterIQ) {
// CHECKSTYLE:OFF
this.filterIQ = filterIQ;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or denies incoming messages or not.
@ -158,8 +165,10 @@ public class PrivacyItem {
* @return the message filtering status.
*/
public boolean isFilterMessage() {
// CHECKSTYLE:OFF
return filterMessage;
}
// CHECKSTYLE:ON
/**
* Sets wheather the receiver allows or denies incoming messages or not.
@ -167,8 +176,10 @@ public class PrivacyItem {
* @param filterMessage indicates if the receiver allows or denies incoming messages or not.
*/
public void setFilterMessage(boolean filterMessage) {
// CHECKSTYLE:OFF
this.filterMessage = filterMessage;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or denies incoming presence or not.
@ -176,8 +187,10 @@ public class PrivacyItem {
* @return the iq filtering incoming presence status.
*/
public boolean isFilterPresenceIn() {
// CHECKSTYLE:OFF
return filterPresenceIn;
}
// CHECKSTYLE:ON
/**
* Sets whether the receiver allows or denies incoming presence or not.
@ -185,8 +198,10 @@ public class PrivacyItem {
* @param filterPresenceIn indicates if the receiver allows or denies filtering incoming presence.
*/
public void setFilterPresenceIn(boolean filterPresenceIn) {
// CHECKSTYLE:OFF
this.filterPresenceIn = filterPresenceIn;
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or denies incoming presence or not.
@ -194,8 +209,10 @@ public class PrivacyItem {
* @return the iq filtering incoming presence status.
*/
public boolean isFilterPresenceOut() {
// CHECKSTYLE:OFF
return filterPresenceOut;
}
// CHECKSTYLE:ON
/**
* Sets whether the receiver allows or denies outgoing presence or not.
@ -203,8 +220,10 @@ public class PrivacyItem {
* @param filterPresenceOut indicates if the receiver allows or denies filtering outgoing presence
*/
public void setFilterPresenceOut(boolean filterPresenceOut) {
// CHECKSTYLE:OFF
this.filterPresenceOut = filterPresenceOut;
}
// CHECKSTYLE:ON
/**
* Returns the order where the receiver is processed. List items are processed in
@ -216,8 +235,10 @@ public class PrivacyItem {
* @return the order number.
*/
public long getOrder() {
// CHECKSTYLE:OFF
return order;
}
// CHECKSTYLE:ON
/**
* Returns the type hold the kind of communication it will allow or block.
@ -227,7 +248,9 @@ public class PrivacyItem {
*/
public Type getType() {
return type;
// CHECKSTYLE:OFF
}
// CHECKSTYLE:ON
/**
* Returns the element identifier to apply the action.
@ -242,7 +265,9 @@ public class PrivacyItem {
*/
public String getValue() {
return value;
// CHECKSTYLE:OFF
}
// CHECKSTYLE:ON
/**
* Returns whether the receiver allows or denies every kind of communication.
@ -253,6 +278,7 @@ public class PrivacyItem {
* @return the all communications status.
*/
public boolean isFilterEverything() {
// CHECKSTYLE:OFF
return !(this.isFilterIQ() || this.isFilterMessage() || this.isFilterPresenceIn()
|| this.isFilterPresenceOut());
}
@ -295,6 +321,7 @@ public class PrivacyItem {
}
buf.append("</item>");
}
// CHECKSTYLE:ON
return buf.toString();
}

View file

@ -45,6 +45,7 @@ public class PrivacyProvider extends IQProvider<Privacy> {
while (!done) {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
// CHECKSTYLE:OFF
if (parser.getName().equals("active")) {
String activeName = parser.getAttributeValue("", "name");
if (activeName == null) {
@ -61,6 +62,7 @@ public class PrivacyProvider extends IQProvider<Privacy> {
privacy.setDefaultName(defaultName);
}
}
// CHECKSTYLE:ON
else if (parser.getName().equals("list")) {
parseList(parser, privacy);
}
@ -84,7 +86,9 @@ public class PrivacyProvider extends IQProvider<Privacy> {
int eventType = parser.next();
if (eventType == XmlPullParser.START_TAG) {
if (parser.getName().equals("item")) {
// CHECKSTYLE:OFF
items.add(parseItem(parser));
// CHECKSTYLE:ON
}
}
else if (eventType == XmlPullParser.END_TAG) {
@ -95,10 +99,12 @@ public class PrivacyProvider extends IQProvider<Privacy> {
}
privacy.setPrivacyList(listName, items);
// CHECKSTYLE:OFF
}
// Parse the list complex type
private static PrivacyItem parseItem(XmlPullParser parser) throws XmlPullParserException, IOException, SmackException {
// CHECKSTYLE:ON
// Retrieves the required attributes
String actionValue = parser.getAttributeValue("", "action");
// Set the order number, this attribute is required
@ -135,7 +141,9 @@ public class PrivacyProvider extends IQProvider<Privacy> {
}
parseItemChildElements(parser, item);
return item;
// CHECKSTYLE:OFF
}
// CHECKSTYLE:ON
private static void parseItemChildElements(XmlPullParser parser, PrivacyItem privacyItem) throws XmlPullParserException, IOException {
final int initialDepth = parser.getDepth();

View file

@ -85,7 +85,9 @@ public class Item extends NodeExtension
*/
public Item(String itemId, String nodeId)
{
// CHECKSTYLE:OFF
super(PubSubElementType.ITEM_EVENT, nodeId);
// CHECKSTYLE:ON
id = itemId;
}

View file

@ -26,6 +26,8 @@ import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jivesoftware.smack.SmackException;
@ -36,6 +38,7 @@ import org.jivesoftware.smack.SmackException;
* @author Henning Staib
*/
public class Socks5TestProxy {
private static final Logger LOGGER = Logger.getLogger(Socks5TestProxy.class.getName());
/* SOCKS5 proxy singleton */
private static Socks5TestProxy socks5Server;
@ -102,7 +105,7 @@ public class Socks5TestProxy {
this.serverThread.start();
}
catch (IOException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
// do nothing
}
}
@ -120,7 +123,7 @@ public class Socks5TestProxy {
}
catch (IOException e) {
// do nothing
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
}
if (this.serverThread != null && this.serverThread.isAlive()) {
@ -130,7 +133,7 @@ public class Socks5TestProxy {
}
catch (InterruptedException e) {
// do nothing
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
}
}
this.serverThread = null;
@ -176,7 +179,7 @@ public class Socks5TestProxy {
try {
wait(5000);
} catch (InterruptedException e) {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
} finally {
if (!startupComplete) {
throw new IllegalStateException("Startup of Socks5TestProxy failed within 5 seconds");
@ -230,7 +233,7 @@ public class Socks5TestProxy {
}
catch (Exception e) {
try {
e.printStackTrace();
LOGGER.log(Level.SEVERE, "exception", e);
socket.close();
}
catch (IOException e1) {

View file

@ -124,6 +124,7 @@ public class Protocol {
*/
@SuppressWarnings("unchecked")
public void verifyAll() {
// CHECKSTYLE:OFF
assertEquals(requests.size(), responsesList.size());
if (printProtocol)
@ -154,6 +155,7 @@ public class Protocol {
}
if (printProtocol)
System.out.println("=================== End =================\n");
// CHECKSTYLE:ON
}
/**