Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2533 from sjrd/small-javalib-changes
Small javalib changes
- Loading branch information
Showing
4 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package java.util | ||
|
||
class EventObject(protected var source: AnyRef) { | ||
def getSource(): AnyRef = source | ||
|
||
override def toString(): String = | ||
s"${getClass.getSimpleName}[source=$source]" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/EventObjectTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* __ *\ | ||
** ________ ___ / / ___ __ ____ Scala.js Test Suite ** | ||
** / __/ __// _ | / / / _ | __ / // __/ (c) 2013-2016, LAMP/EPFL ** | ||
** __\ \/ /__/ __ |/ /__/ __ |/_// /_\ \ http://scala-js.org/ ** | ||
** /____/\___/_/ |_/____/_/ | |__/ /____/ ** | ||
** |/____/ ** | ||
\* */ | ||
package org.scalajs.testsuite.javalib.util | ||
|
||
import org.junit.Test | ||
import org.junit.Assert._ | ||
|
||
import java.util.EventObject | ||
|
||
class EventObjectTest { | ||
@Test def getSource(): Unit = { | ||
val src = new AnyRef | ||
val e = new EventObject(src) | ||
assertSame(src, e.getSource) | ||
} | ||
|
||
/* #2532 This does not link, because we cannot declare a Java field | ||
@Test def sourceField(): Unit = { | ||
class E(s: AnyRef) extends EventObject(s) { | ||
def setSource(s: AnyRef): Unit = source = s | ||
def otherGetSource: AnyRef = source | ||
} | ||
val src1 = new AnyRef | ||
val e = new E(src1) | ||
assertSame(src1, e.otherGetSource) | ||
val src2 = new AnyRef | ||
e.setSource(src2) | ||
assertSame(src2, e.otherGetSource) | ||
assertSame(src2, e.getSource) | ||
} | ||
*/ | ||
|
||
@Test def testToString(): Unit = { | ||
/* There is not much we can test about toString, but it should not be the | ||
* default inherited from Object. | ||
*/ | ||
val e = new EventObject(new AnyRef) | ||
assertNotNull(e.toString()) | ||
val default = classOf[EventObject].getName + "@" + Integer.toHexString(e.##) | ||
assertNotEquals(default, e.toString()) | ||
} | ||
} |