Skip to content

Commit d151fe7

Browse files
committed
Add a test for java.lang.String#hashCode()
1 parent 935e4de commit d151fe7

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

tests/Packages/JavaLangStringTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,24 @@ public function testConcat()
8585
$this->assertEquals('abcdef', $value);
8686
}
8787

88+
public function testHashCode()
89+
{
90+
ob_start();
91+
$this->initiatedJavaClasses['JavaUtilStringTest']
92+
->getInvoker()
93+
->getStatic()
94+
->getMethods()
95+
->call(
96+
'testHashCode'
97+
);
98+
99+
$values = array_filter(explode("\n", ob_get_clean()));
100+
$this->assertCount(3, $values);
101+
$this->assertSame('2728214739616339340', $values[0]);
102+
$this->assertSame('2728214739616339340', $values[1]);
103+
$this->assertSame('2728214739616339340', $values[2]);
104+
}
105+
88106
public function testReplace()
89107
{
90108
ob_start();

tests/fixtures/java/JavaLangStringTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ public static void concat(String a, String b)
1010
System.out.print(a.concat(b));
1111
}
1212

13+
public static void testHashCode()
14+
{
15+
System.out.println(Objects.hashCode("hello, world"));
16+
System.out.println(Objects.hashCode("HELLO, WORLD".toLowerCase()));
17+
System.out.println(Objects.hashCode(new String("hello, world")));
18+
}
19+
1320
public static void replace(String a, String b, String c)
1421
{
1522
System.out.print(a.replace(b, c));

0 commit comments

Comments
 (0)