forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntegerExampleTest.java
More file actions
77 lines (63 loc) · 1.63 KB
/
IntegerExampleTest.java
File metadata and controls
77 lines (63 loc) · 1.63 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package com.examplehub.basics.number;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class IntegerExampleTest {
@Test
void testValueOf() {
Integer integer = Integer.valueOf(100);
System.out.println(integer);
assertEquals(100, integer.intValue());
integer = Integer.valueOf("123");
System.out.println(integer);
assertEquals(123, integer.intValue());
integer = Integer.valueOf("a", 16);
System.out.println(integer);
assertEquals(10, integer.intValue());
}
@Test
void testParseInt() {
int number = Integer.parseInt("123");
System.out.println(number);
assertEquals(123, number);
assertThrows(
NumberFormatException.class,
() -> {
int num = Integer.parseInt("123a");
fail();
});
}
@Test
void testAutoBoxing() {
Integer integer = 10;
assertEquals(10, integer.intValue());
Integer integer1 = 10;
assertTrue(integer == integer1);
assertTrue(integer.equals(integer1));
Integer first = 128;
Integer second = 128;
System.out.println(first == second);
assertNotSame(first, second);
}
@Test
void testAutoBoxingNullPointer() {
Integer integer = null;
try {
int intVal = integer;
fail(); // won't happen
} catch (NullPointerException nullPointerException) {
assertTrue(true);
}
}
@Test
void testToBinaryString() {
assertEquals("1010", Integer.toBinaryString(10));
}
@Test
void testToOctalString() {
assertEquals("12", Integer.toOctalString(10));
}
@Test
void test() {
assertEquals("a", Integer.toHexString(10));
}
}