mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2024-11-22 06:12:05 +01:00
Adjust AbstractListFilter.toString()
to produce a similar styled output like the other toString() methods and add unit-test for the method.
This commit is contained in:
parent
4b7a396b9b
commit
49e1c837b2
2 changed files with 50 additions and 3 deletions
|
@ -19,6 +19,7 @@ package org.jivesoftware.smack.filter;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.util.Objects;
|
||||
|
@ -68,9 +69,13 @@ public abstract class AbstractListFilter implements PacketFilter {
|
|||
public final String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" (");
|
||||
for (PacketFilter filter : filters) {
|
||||
sb.append(' ' + filter.toString() + ',');
|
||||
sb.append(": (");
|
||||
for (Iterator<PacketFilter> it = filters.iterator(); it.hasNext();) {
|
||||
PacketFilter filter = it.next();
|
||||
sb.append(filter.toString());
|
||||
if (it.hasNext()) {
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2015 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.filters;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.jivesoftware.smack.filter.AndFilter;
|
||||
import org.jivesoftware.smack.filter.MessageWithBodiesFilter;
|
||||
import org.jivesoftware.smack.filter.StanzaIdFilter;
|
||||
import org.jivesoftware.smack.filter.ThreadFilter;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class FilterToStringTest {
|
||||
|
||||
@Test
|
||||
public void abstractListFilterToStringTest() {
|
||||
AndFilter andFilter = new AndFilter();
|
||||
andFilter.addFilter(new StanzaIdFilter("foo"));
|
||||
andFilter.addFilter(new ThreadFilter("42"));
|
||||
andFilter.addFilter(MessageWithBodiesFilter.INSTANCE);
|
||||
|
||||
final String res =andFilter.toString();
|
||||
assertEquals("AndFilter: (StanzaIdFilter: id=foo, ThreadFilter: thread=42, MessageWithBodiesFilter)", res);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue