Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create java test. Fix #443 #446

Merged
merged 3 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ allprojects {
}

subprojects {
if ([email protected] == "java-test") {
return@subprojects
}
afterEvaluate {
apply(plugin = "com.github.johnrengelman.shadow")
val kotlin =
Expand Down
40 changes: 40 additions & 0 deletions java-test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/


plugins {
java
}


dependencies {

implementation(project(":mirai-core"))

implementation(project(":mirai-serialization"))

testImplementation(group = "junit", name = "junit", version = "4.12")

implementation(kotlin("stdlib", null))
implementation(kotlin("serialization", null))
implementation(kotlin("reflect", null))


implementation(kotlinx("serialization-runtime-common", Versions.Kotlin.serialization))
implementation(kotlinx("serialization-protobuf-common", Versions.Kotlin.serialization))
implementation(kotlinx("io", Versions.Kotlin.io))
implementation(kotlinx("coroutines-io", Versions.Kotlin.coroutinesIo))
implementation(kotlinx("coroutines-core-common", Versions.Kotlin.coroutines))

implementation("org.jetbrains.kotlinx:atomicfu-common:${Versions.Kotlin.atomicFU}")

implementation(ktor("client-cio", Versions.Kotlin.ktor))
implementation(ktor("client-core", Versions.Kotlin.ktor))
implementation(ktor("network", Versions.Kotlin.ktor))

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 Mamoe Technologies and contributors.
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/

package net.mamoe.mirai.javatest;

import kotlin.coroutines.CoroutineContext;
import kotlin.coroutines.EmptyCoroutineContext;
import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.CoroutineScopeKt;
import net.mamoe.mirai.event.*;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

public class SimpleListenerHostTest {
@Test
public void test() {
final SimpleListenerHost host = new SimpleListenerHost() {
@EventHandler
public void testListen(
AbstractEvent event
) {
System.out.println(event);
}

@Override
public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) {
exception.printStackTrace();
}
};
CoroutineScope scope = CoroutineScopeKt.CoroutineScope(EmptyCoroutineContext.INSTANCE);
Events.registerEvents(scope, host);
EventKt.broadcast(new AbstractEvent() {
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,11 @@ private fun Method.registerEvent(
}
} else {
// java methods

check(this.parameterCount == 1) {
"Illegal method parameter. Only one parameter is required."
}
val paramType = this.parameters[0].type
check(this.parameterCount == 1 && Event::class.java.isAssignableFrom(paramType)) {
check(Event::class.java.isAssignableFrom(paramType)) {
"Illegal method parameter. Required one exact Event subclass. found $paramType"
}
when (this.returnType) {
Expand All @@ -347,11 +349,11 @@ private fun Method.registerEvent(
if (annotation.ignoreCancelled) {
if ((this as? CancellableEvent)?.isCancelled != true) {
withContext(Dispatchers.IO) {
[email protected](owner, this)
[email protected](owner, this@subscribeAlways)
}
}
} else withContext(Dispatchers.IO) {
[email protected](owner, this)
[email protected](owner, this@subscribeAlways)
}
}
}
Expand All @@ -365,11 +367,11 @@ private fun Method.registerEvent(
if (annotation.ignoreCancelled) {
if ((this as? CancellableEvent)?.isCancelled != true) {
withContext(Dispatchers.IO) {
[email protected](owner, this) as ListeningStatus
[email protected](owner, this@subscribe) as ListeningStatus
}
} else ListeningStatus.LISTENING
} else withContext(Dispatchers.IO) {
[email protected](owner, this) as ListeningStatus
[email protected](owner, this@subscribe) as ListeningStatus
}

}
Expand Down
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rootProject.name = 'mirai'
include(':mirai-core')
include(':mirai-core-qqandroid')
include(':mirai-serialization')
include(':java-test')
//include(':compatibility-validator') // THIS WILL CAUSE A DEPENDENCY RESOLUTION BUG
//include(':java-compatibility-validator')

Expand Down