GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add ClassMethodUtils (#135) · voidframework/voidframework@aa2518a

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • voidframework-core/src
    • main/java/dev/voidframework/core/utils
      • ClassMethodUtils.java
    • test/java/dev/voidframework/core/utils
      • ClassMethodUtilsTest.java
      • ClassResolverUtilsTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎voidframework-core/src/main/java/dev/voidframework/core/utils/ClassMethodUtils.java‎

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package dev.voidframework.core.utils;
2+
3+
import dev.voidframework.core.constant.StringConstants;
4+
5+
import java.lang.reflect.Method;
6+
import java.util.StringJoiner;
7+
8+
/**
9+
* Utility methods for class method.
10+
*
11+
* @since 1.12.0
12+
*/
13+
public final class ClassMethodUtils {
14+
15+
/**
16+
* Default constructor.
17+
*
18+
* @since 1.12.0
19+
*/
20+
private ClassMethodUtils() {
21+
22+
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
23+
}
24+
25+
/**
26+
* Creates method's short signature.
27+
*
28+
* @param method Method for which create the short signature
29+
* @return Short signature of the method
30+
* @since 1.12.0
31+
*/
32+
public static String toShortSignature(final Method method) {
33+
34+
if (method == null) {
35+
return null;
36+
}
37+
38+
final StringJoiner stringJoiner = new StringJoiner(
39+
StringConstants.COMMA,
40+
method.getName() + StringConstants.PARENTHESIS_OPEN,
41+
StringConstants.PARENTHESIS_CLOSE);
42+
43+
for (final Class<?> parameterType : method.getParameterTypes()) {
44+
stringJoiner.add(parameterType.getTypeName());
45+
}
46+
47+
return stringJoiner.toString();
48+
}
49+
}
Collapse file

‎voidframework-core/src/test/java/dev/voidframework/core/utils/ClassMethodUtilsTest.java‎

Copy file name to clipboard
+64Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package dev.voidframework.core.utils;
2+
3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.MethodOrderer;
5+
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.api.TestMethodOrder;
7+
8+
import java.lang.reflect.Constructor;
9+
import java.lang.reflect.InvocationTargetException;
10+
import java.lang.reflect.Method;
11+
import java.util.Optional;
12+
13+
@TestMethodOrder(MethodOrderer.MethodName.class)
14+
final class ClassMethodUtilsTest {
15+
16+
@Test
17+
void constructor() throws NoSuchMethodException {
18+
19+
// Act
20+
final Constructor<ClassMethodUtils> constructor = ClassMethodUtils.class.getDeclaredConstructor();
21+
constructor.setAccessible(true);
22+
23+
final InvocationTargetException exception = Assertions.assertThrows(InvocationTargetException.class, constructor::newInstance);
24+
25+
// Assert
26+
Assertions.assertNotNull(exception.getCause());
27+
Assertions.assertEquals("This is a utility class and cannot be instantiated", exception.getCause().getMessage());
28+
}
29+
30+
@Test
31+
void toShortSignature() throws NoSuchMethodException {
32+
33+
// Arrange
34+
final Method method = Dummy.class.getMethod("findById", String.class);
35+
36+
// Act
37+
final String shortSignature = ClassMethodUtils.toShortSignature(method);
38+
39+
// Assert
40+
Assertions.assertNotNull(shortSignature);
41+
Assertions.assertEquals("findById(java.lang.String)", shortSignature);
42+
}
43+
44+
@Test
45+
void toShortSignatureWithNullValue() {
46+
47+
// Act
48+
final String shortSignature = ClassMethodUtils.toShortSignature(null);
49+
50+
// Assert
51+
Assertions.assertNull(shortSignature);
52+
}
53+
54+
/**
55+
* Simple dummy class.
56+
*/
57+
public static class Dummy {
58+
59+
public Optional<Object> findById(final String id) {
60+
61+
return Optional.of(id);
62+
}
63+
}
64+
}
Collapse file

‎voidframework-core/src/test/java/dev/voidframework/core/utils/ClassResolverUtilsTest.java‎

Copy file name to clipboardExpand all lines: voidframework-core/src/test/java/dev/voidframework/core/utils/ClassResolverUtilsTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void forNameWithExplicitClassLoader() {
6666

6767
// Assert
6868
Assertions.assertNotNull(classType);
69-
Assertions.assertEquals(classType, ClassResolverUtils.class);
69+
Assertions.assertEquals(ClassResolverUtils.class, classType);
7070
}
7171

7272
@Test

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.