Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/Packages/JavaLangStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ public function testConcat()
$this->assertEquals('abcdef', $value);
}

public function testHashCode()
{
ob_start();
$this->initiatedJavaClasses['JavaLangStringTest']
->getInvoker()
->getStatic()
->getMethods()
->call(
'testHashCode'
);

$values = array_filter(explode("\n", ob_get_clean()));
$this->assertCount(3, $values);
$this->assertSame('2728214739616339340', $values[0]);
$this->assertSame('2728214739616339340', $values[1]);
$this->assertSame('2728214739616339340', $values[2]);
}

public function testReplace()
{
ob_start();
Expand Down
35 changes: 35 additions & 0 deletions tests/Packages/JavaLangSystemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace PHPJava\Tests\Packages;

use PHPJava\Core\JavaArchive;
use PHPJava\Tests\Base;

class JavaLangSystemTest extends Base
{
protected $fixtures = [
'JavaLangSystemTest',
];

public function testIdentityHashCode()
{
ob_start();
$this->initiatedJavaClasses['JavaLangSystemTest']
->getInvoker()
->getStatic()
->getMethods()
->call(
'identityHashCode'
);

$values = array_filter(explode("\n", ob_get_clean()));
$this->assertCount(2, $values);

$hashCodes = [];

foreach ($values as $value) {
$this->assertIsNumeric($value);
$this->assertNotContains($value, $hashCodes);
$hashCodes[] = $value;
}
}
}
30 changes: 30 additions & 0 deletions tests/Packages/JavaUtilObjectsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
namespace PHPJava\Tests\Packages;

use PHPJava\Core\JavaArchive;
use PHPJava\Tests\Base;

class JavaUtilObjectsTest extends Base
{
protected $fixtures = [
'JavaUtilObjectsTest',
];

public function testHashCode()
{
ob_start();
$this->initiatedJavaClasses['JavaUtilObjectsTest']
->getInvoker()
->getStatic()
->getMethods()
->call(
'testHashCode'
);

$values = array_filter(explode("\n", ob_get_clean()));
$this->assertCount(3, $values);
$this->assertSame('2728214739616339340', $values[0]);
$this->assertSame('2728214739616339340', $values[1]);
$this->assertSame('2728214739616339340', $values[2]);
}
}
7 changes: 7 additions & 0 deletions tests/fixtures/java/JavaLangStringTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ public static void concat(String a, String b)
System.out.print(a.concat(b));
}

public static void testHashCode()
{
System.out.println("hello, world".hashCode());
System.out.println("HELLO, WORLD".toLowerCase().hashCode());
System.out.println((new String("hello, world")).hashCode());
}

public static void replace(String a, String b, String c)
{
System.out.print(a.replace(b, c));
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/java/JavaLangSystemTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class JavaLangSystemTest
{
public static void identityHashCode()
{
System.out.println(System.identityHashCode("Hello, World"));
System.out.println(System.identityHashCode(new String("Hello, World")));
}
}
11 changes: 11 additions & 0 deletions tests/fixtures/java/JavaUtilObjectsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import java.util.Objects;

class JavaUtilObjectsTest
{
public static void testHashCode()
{
System.out.println(Objects.hashCode("hello, world"));
System.out.println(Objects.hashCode("HELLO, WORLD".toLowerCase()));
System.out.println(Objects.hashCode(new String("hello, world")));
}
}