mirror of
https://codeberg.org/Mercury-IM/Smack
synced 2025-09-09 10:19:41 +02:00
Introduce test fixtures
This also removes the powermock dependency. Although powermock is a fine library, it currently prevents dropping Junit4. And since we only use the Whitebox API of powermock, this simply replaced powermock's Whitebox with our own.
This commit is contained in:
parent
4a99f7252c
commit
b5f9d4d7a3
51 changed files with 123 additions and 80 deletions
|
@ -10,10 +10,19 @@ dependencies {
|
|||
compile "org.jxmpp:jxmpp-core:$jxmppVersion"
|
||||
compile "org.jxmpp:jxmpp-jid:$jxmppVersion"
|
||||
compile "org.minidns:minidns-core:$miniDnsVersion"
|
||||
testCompile project(':smack-xmlparser-stax')
|
||||
testCompile project(':smack-xmlparser-xpp3')
|
||||
testCompile "org.jxmpp:jxmpp-jid:$jxmppVersion:tests"
|
||||
testCompile "org.xmlunit:xmlunit-core:$xmlUnitVersion"
|
||||
|
||||
testFixturesImplementation project(':smack-xmlparser-stax')
|
||||
testFixturesImplementation project(':smack-xmlparser-xpp3')
|
||||
|
||||
// Bouncy Castle is setup by SmackTestSuite. We deliberately use
|
||||
// 'implementation' here since there is no need to shadow it
|
||||
// outside of the fixtures compilation classpath. That is, no test
|
||||
// should ever setup Bouncy Castle as security provider explicitly.
|
||||
testFixturesImplementation 'org.bouncycastle:bcprov-jdk15on:1.64'
|
||||
testFixturesImplementation 'org.apache.commons:commons-lang3:3.10'
|
||||
|
||||
testFixturesApi "org.jxmpp:jxmpp-jid:$jxmppVersion:tests"
|
||||
testFixturesApi "org.xmlunit:xmlunit-core:$xmlUnitVersion"
|
||||
// Explictily add assertj-core which is a dependency of
|
||||
// xmlunit-assertj, but gradle fails to resolves it with:
|
||||
// Execution failed for task ':smack-core:compileTestJava'.
|
||||
|
@ -21,12 +30,9 @@ dependencies {
|
|||
// > Could not find org.assertj:assertj-core:.
|
||||
// Required by:
|
||||
// project :smack-core > org.xmlunit:xmlunit-assertj:2.6.2
|
||||
testCompile "org.assertj:assertj-core:3.11.1"
|
||||
testCompile "org.xmlunit:xmlunit-assertj:$xmlUnitVersion"
|
||||
testCompile 'com.jamesmurty.utils:java-xmlbuilder:1.2'
|
||||
testCompile 'org.bouncycastle:bcprov-jdk15on:1.64'
|
||||
testCompile 'com.google.guava:guava:28.2-jre'
|
||||
testCompile 'org.jgrapht:jgrapht-io:1.3.1'
|
||||
testFixturesApi "org.assertj:assertj-core:3.11.1"
|
||||
testFixturesApi "org.xmlunit:xmlunit-assertj:$xmlUnitVersion"
|
||||
testFixturesApi 'org.hamcrest:hamcrest-library:2.2'
|
||||
}
|
||||
|
||||
class CreateFileTask extends DefaultTask {
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jivesoftware.smack;
|
||||
|
||||
import java.io.IOException;
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright © 2014 Florian Schmaus
|
||||
* Copyright © 2014-2020 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,7 +17,6 @@
|
|||
package org.jivesoftware.smack.test.util;
|
||||
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Factory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
|
||||
|
@ -40,7 +39,6 @@ public class CharSequenceEquals extends TypeSafeMatcher<CharSequence> {
|
|||
return charSequenceString.equals(itemString);
|
||||
}
|
||||
|
||||
@Factory
|
||||
public static Matcher<CharSequence> equalsCharSequence(CharSequence charSequence) {
|
||||
return new CharSequenceEquals(charSequence);
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2019 Florian Schmaus
|
||||
* Copyright 2019-2020 Florian Schmaus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -14,9 +14,9 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
package org.jivesoftware.smack.test.util;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.lang.ref.PhantomReference;
|
||||
|
@ -129,7 +129,7 @@ public class MemoryLeakTestUtil {
|
|||
}
|
||||
|
||||
Reference<?> reference = referenceQueue.poll();
|
||||
assertNull("Reference queue is not empty when it should be", reference);
|
||||
assertNull(reference, "Reference queue is not empty when it should be");
|
||||
}
|
||||
|
||||
private static void assertReferencesQueueIsEmpty(ReferenceQueue<?> referenceQueue) {
|
|
@ -14,7 +14,7 @@
|
|||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
package org.jivesoftware.smack.test.util;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.BindException;
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2020 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.test.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import org.apache.commons.lang3.reflect.FieldUtils;
|
||||
|
||||
public class Whitebox {
|
||||
|
||||
public static <T> T getInternalState(Object object, String fieldName, Class<T> fieldType) {
|
||||
Class<?> objectClass = object.getClass();
|
||||
|
||||
Field field = FieldUtils.getField(objectClass, fieldName, true);
|
||||
|
||||
Object res;
|
||||
try {
|
||||
res = field.get(object);
|
||||
} catch (IllegalArgumentException | IllegalAccessException e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
|
||||
if (!fieldType.isInstance(res)) {
|
||||
throw new AssertionError(res + " is not a (sub)type of " + fieldType);
|
||||
}
|
||||
|
||||
return fieldType.cast(res);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue