-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringPoolTest.java
More file actions
52 lines (40 loc) · 1.08 KB
/
StringPoolTest.java
File metadata and controls
52 lines (40 loc) · 1.08 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
package basics;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class StringPoolTest {
@Test
public void sameMemoryTest() {
//given
String s1 = "minseok";
String s2 = "minseok";
//then
Assertions.assertTrue(s1 == s2);
}
@Test
public void new로_생성한객체는_같은메모리를_공유하지않는다() {
//given
String s1 = new String("minseok");
String s2 = new String("minseok");
//then
Assertions.assertFalse(s1 == s2);
}
@Test
public void new로_생성한객체와_리터럴String은_동일하지않다() {
//given
String s1 = "minseok";
String s2 = new String("minseok");
//then
Assertions.assertFalse(s1 == s2);
}
@Test
public void InterningTest() {
//given
String s1 = "minseok";
String s2 = new String("minseok");
//when
Assertions.assertFalse(s1 == s2);
s2 = s2.intern();
//then
Assertions.assertTrue(s1 == s2);
}
}