Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
56 lines (44 loc) · 2.08 KB

File metadata and controls

56 lines (44 loc) · 2.08 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.h2;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.function.Try;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Optional;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.platform.commons.util.ReflectionUtils.*;
public class AppTest {
private final String classToFind = "com.h2.App";
public Optional<Class<?>> getAppClass() {
Try<Class<?>> aClass = tryToLoadClass(classToFind);
return aClass.toOptional();
}
@Test
public void assertClassExistence() {
final Optional<Class<?>> maybeClass = getAppClass();
assertTrue(maybeClass.isPresent(), classToFind + " should be present");
assertEquals(classToFind, maybeClass.get().getCanonicalName());
}
@Test
public void assertPrivateMethodExistence() {
final String methodName = "add";
final Optional<Class<?>> maybeClass = getAppClass();
Class<?> aClass = maybeClass.get();
Optional<Method> maybeMethod = findMethod(aClass, methodName, int[].class);
assertTrue(maybeMethod.isPresent(), methodName + " should be present in " + aClass.getCanonicalName());
final Method method = maybeMethod.get();
assertTrue(isPrivate(method), methodName + " should be private");
assertEquals(int.class, method.getReturnType(), methodName + " should return type should be 'int'");
Parameter[] parameters = method.getParameters();
assertEquals(1, parameters.length, methodName + " should have 1 parameter");
assertEquals(int[].class, parameters[0].getType(), methodName + " parameter should be of type 'int[]'");
assertTrue(isStatic(method), methodName + "should be static method");
assertTrue(isPrivate(method), methodName + "should be private method");
}
@Test
public void testDoubleTheNumber() {
for (int i = 1; i < 10; i++) {
assertEquals(2 * i, App.doubleTheNumber(i), i + " should be " + 2 * i);
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.