Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add tests for #133
  • Loading branch information
chitoku-k committed May 7, 2019
commit 935e4de1072a33abd7836ae2e62218dc1ea09b7e
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]);
}
}
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")));
}
}