-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct KeyValuePair equals and add coverage for ServiceLocator (#…
…257) Signed-off-by: Nathan Klick <[email protected]> Signed-off-by: Jeromy Cannon <[email protected]> Co-authored-by: Nathan Klick <[email protected]>
- Loading branch information
1 parent
7f051c0
commit 5b17978
Showing
13 changed files
with
228 additions
and
4 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
34 changes: 34 additions & 0 deletions
34
...se-api/src/test/java/com/hedera/fullstack/base/api/test/collections/KeyValuePairTest.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,34 @@ | ||
/* | ||
* Copyright (C) 2023 Hedera Hashgraph, LLC | ||
* | ||
* 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 com.hedera.fullstack.base.api.test.collections; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.hedera.fullstack.base.api.collections.KeyValuePair; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class KeyValuePairTest { | ||
@Test | ||
@DisplayName("Test KeyValuePair") | ||
void testKeyValuePair() { | ||
KeyValuePair<String, String> kvp1 = new KeyValuePair<>("key", "value"); | ||
KeyValuePair<String, String> kvp1v2 = new KeyValuePair<>("key", "value2"); | ||
assertThat(kvp1).isNotEqualTo(kvp1v2); | ||
assertThat(kvp1.hashCode()).isEqualTo(kvp1v2.hashCode()); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...ase-api/src/test/java/com/hedera/fullstack/base/api/test/reflect/ReflectionUtilsTest.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,60 @@ | ||
/* | ||
* Copyright (C) 2023 Hedera Hashgraph, LLC | ||
* | ||
* 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 com.hedera.fullstack.base.api.test.reflect; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.jupiter.api.Named.named; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
import com.hedera.fullstack.base.api.reflect.ReflectionUtils; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class ReflectionUtilsTest { | ||
static Stream<Arguments> primitiveAndWrapperSupplier() { | ||
return Stream.of( | ||
arguments(named("void.class", void.class), named("Void.class", Void.class)), | ||
arguments(named("boolean.class", boolean.class), named("Boolean.class", Boolean.class)), | ||
arguments(named("byte.class", byte.class), named("Byte.class", Byte.class)), | ||
arguments(named("char.class", char.class), named("Character.class", Character.class)), | ||
arguments(named("short.class", short.class), named("Short.class", Short.class)), | ||
arguments(named("int.class", int.class), named("Integer.class", Integer.class)), | ||
arguments(named("long.class", long.class), named("Long.class", Long.class)), | ||
arguments(named("float.class", float.class), named("Float.class", Float.class)), | ||
arguments(named("double.class", double.class), named("Double.class", Double.class)), | ||
arguments(named("String.class", String.class), named("String.class", String.class))); | ||
} | ||
|
||
@ParameterizedTest(name = "Validate wrapper for {0}") | ||
@MethodSource("primitiveAndWrapperSupplier") | ||
@DisplayName("Test primitive as wrapper class") | ||
void testPrimitiveAsWrapperClass(Class<?> primitiveClass, Class<?> wrapperClass) { | ||
Class<?> result = ReflectionUtils.primitiveAsWrapperClass(primitiveClass); | ||
assertThat(result).isEqualTo(wrapperClass); | ||
} | ||
|
||
@ParameterizedTest(name = "Validate primitive for {1}") | ||
@MethodSource("primitiveAndWrapperSupplier") | ||
@DisplayName("Test wrapper as primitive class") | ||
void testWrapperAsPrimitiveClass(Class<?> primitiveClass, Class<?> wrapperClass) { | ||
Class<?> result = ReflectionUtils.wrapperAsPrimitiveClass(wrapperClass); | ||
assertThat(result).isEqualTo(primitiveClass); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ase-api/src/test/java/com/hedera/fullstack/base/api/test/resource/ResourceLoaderTest.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,52 @@ | ||
/* | ||
* Copyright (C) 2023 Hedera Hashgraph, LLC | ||
* | ||
* 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 com.hedera.fullstack.base.api.test.resource; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
import com.hedera.fullstack.base.api.resource.ResourceLoader; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class ResourceLoaderTest { | ||
@Test | ||
@DisplayName("Verify load works as expected") | ||
void testLoad() throws IOException { | ||
ResourceLoader<ResourceLoaderTest> resourceLoader = new ResourceLoader<>(ResourceLoaderTest.class); | ||
Path resourcePath = resourceLoader.load("resource.txt"); | ||
assertThat(resourcePath) | ||
.exists() | ||
.isRegularFile() | ||
.hasFileName("resource.txt") | ||
.isWritable() | ||
.isReadable() | ||
.isExecutable(); | ||
} | ||
|
||
@Test | ||
@DisplayName("Verify load fails when called with a non-existent file") | ||
void testLoadIOException() { | ||
ResourceLoader<ResourceLoaderTest> resourceLoader = new ResourceLoader<>(ResourceLoaderTest.class); | ||
assertThatThrownBy(() -> resourceLoader.load("not-resource.txt")).isInstanceOf(IOException.class); | ||
} | ||
} |
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 @@ | ||
This is some text for testing purposes. |
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
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
Binary file not shown.
Empty file.