This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for ExtensionRegistry and GrpcValueUtil, make CodeQL use Ja…
…va 19 instead of 18
- Loading branch information
Showing
6 changed files
with
130 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
server/src/test/java/org/noelware/analytics/tests/server/ExtensionRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* 🐻❄️🌂 analytics-jvm: Client and server implementation of Noelware Analytics in Java, supported for both Java and Kotlin | ||
* Copyright (c) 2022 Noelware <team@noelware.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.noelware.analytics.tests.server; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.noelware.analytics.jvm.server.extensions.ExtensionRegistry; | ||
import org.noelware.analytics.jvm.server.extensions.internal.DefaultExtensionRegistry; | ||
import org.noelware.analytics.jvm.server.extensions.jvm.JvmMemoryPoolsExtension; | ||
import org.noelware.analytics.jvm.server.extensions.jvm.JvmThreadsExtension; | ||
import org.noelware.analytics.jvm.server.extensions.jvm.JvmVersionInfoExtension; | ||
|
||
public class ExtensionRegistryTest { | ||
private static final ExtensionRegistry registry = new DefaultExtensionRegistry(); | ||
|
||
@BeforeAll | ||
public static void beforeRun() { | ||
registry.registerAll(new JvmThreadsExtension(), new JvmMemoryPoolsExtension(), new JvmVersionInfoExtension()); | ||
} | ||
|
||
@Test | ||
public void test_findByClass() { | ||
assertNull(registry.findByClass(JvmThreadsExtension.JvmThreadsData.class)); | ||
assertNotNull(registry.findByClass(JvmThreadsExtension.class)); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
server/src/test/java/org/noelware/analytics/tests/server/GrpcValueUtilTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* 🐻❄️🌂 analytics-jvm: Client and server implementation of Noelware Analytics in Java, supported for both Java and Kotlin | ||
* Copyright (c) 2022 Noelware <team@noelware.org> | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in all | ||
* copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
package org.noelware.analytics.tests.server; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import com.google.protobuf.ListValue; | ||
import com.google.protobuf.Struct; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.noelware.analytics.jvm.server.extensions.jvm.JvmThreadsExtension; | ||
import org.noelware.analytics.jvm.server.util.GrpcValueUtil; | ||
|
||
public class GrpcValueUtilTests { | ||
@Test | ||
public void test_ifValuesAreAcceptable() { | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue("a string owo")); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1)); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1L)); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1f)); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1.0)); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(true)); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(1L)); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(new JvmThreadsExtension().supply())); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(List.of("a", "b", "c"))); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(ListValue.newBuilder().build())); | ||
assertDoesNotThrow(() -> GrpcValueUtil.toValue(Struct.newBuilder().build())); | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
GrpcValueUtil.toValue(new Object()); | ||
}); | ||
|
||
assertThrows(IllegalStateException.class, () -> { | ||
GrpcValueUtil.toValue(Struct.newBuilder()); | ||
}); | ||
} | ||
} |