Skip to content

Commit 7e7a11a

Browse files
committed
Remove ambigouity in AssertThrows.expectThrows overloads.
1 parent 5bd1e50 commit 7e7a11a

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/net/URLDecoderTest.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ class URLDecoderTest {
3636

3737
def unsupportedEncoding(encoded: String, enc: String = utf8): Unit = {
3838
val exception = classOf[UnsupportedEncodingException]
39-
val runnable = throwingRunnable { URLDecoder.decode(encoded, enc) }
40-
assertThrows(exception, runnable)
39+
assertThrows(exception, URLDecoder.decode(encoded, enc))
4140
}
4241

4342
// empty string

test-suite/shared/src/test/scala/org/scalajs/testsuite/junit/JUnitAssertionsTest.scala

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -329,33 +329,30 @@ class JUnitAssertionsTest {
329329

330330
@Test
331331
def testExpectThrows(): Unit = {
332-
testIfAsserts(expectThrows(classOf[Exception],
333-
throwingRunnable { throw new Exception }))
332+
testIfAsserts(expectThrows(classOf[Exception], throw new Exception))
334333
testIfAsserts(expectThrows(classOf[IndexOutOfBoundsException],
335-
throwingRunnable { throw new IndexOutOfBoundsException }))
334+
throw new IndexOutOfBoundsException))
336335

337336
testIfAsserts {
338-
val ex = expectThrows(classOf[Exception],
339-
throwingRunnable { throw new Exception("abc") })
337+
val ex = expectThrows(classOf[Exception], throw new Exception("abc"))
340338
assertEquals(ex.getMessage, "abc")
341339
}
342340

343341
testIfAsserts(expectThrows(classOf[IndexOutOfBoundsException],
344-
throwingRunnable { throw new Exception }), ShallNotPass)
345-
testIfAsserts(expectThrows(classOf[IndexOutOfBoundsException],
346-
throwingRunnable { }), ShallNotPass)
342+
throw new Exception), ShallNotPass)
343+
testIfAsserts(expectThrows(classOf[IndexOutOfBoundsException],()),
344+
ShallNotPass)
347345
}
348346

349347
@Test
350348
def testAssertThrows(): Unit = {
351-
testIfAsserts(assertThrows(classOf[Exception],
352-
throwingRunnable { throw new Exception }))
349+
testIfAsserts(assertThrows(classOf[Exception], throw new Exception))
353350
testIfAsserts(assertThrows(classOf[IndexOutOfBoundsException],
354-
throwingRunnable { throw new IndexOutOfBoundsException }))
351+
throw new IndexOutOfBoundsException))
355352

356353
testIfAsserts(assertThrows(classOf[IndexOutOfBoundsException],
357-
throwingRunnable { throw new Exception }), ShallNotPass)
358-
testIfAsserts(assertThrows(classOf[IndexOutOfBoundsException],
359-
throwingRunnable { }), ShallNotPass)
354+
throw new Exception), ShallNotPass)
355+
testIfAsserts(assertThrows(classOf[IndexOutOfBoundsException], ()),
356+
ShallNotPass)
360357
}
361358
}

test-suite/shared/src/test/scala/org/scalajs/testsuite/utils/AssertThrows.scala

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ object AssertThrows {
44
/** Backport implementation of Assert.assertThrows to be used until JUnit 4.13 is
55
* released. See org.junit.Assert.scala in jUnitRuntime.
66
*/
7-
def assertThrows(expectedThrowable: Class[_ <: Throwable],
7+
private def assertThrowsBackport(expectedThrowable: Class[_ <: Throwable],
88
runnable: ThrowingRunnable): Unit = {
9-
expectThrows(expectedThrowable, runnable)
9+
expectThrowsBackport(expectedThrowable, runnable)
1010
}
1111

1212
/** Backport implementation of Assert.expectThrows to be used until JUnit 4.13 is
1313
* released. See org.junit.Assert.scala in jUnitRuntime.
1414
*/
15-
def expectThrows[T <: Throwable](expectedThrowable: Class[T], runnable: ThrowingRunnable): T = {
15+
private def expectThrowsBackport[T <: Throwable](expectedThrowable: Class[T],
16+
runnable: ThrowingRunnable): T = {
1617
try {
1718
runnable.run()
1819
val message =
@@ -37,16 +38,19 @@ object AssertThrows {
3738
/** Backport implementation of Assert.ThrowingRunnable to be used until
3839
* JUnit 4.13 is released. See org.junit.Assert.scala in jUnitRuntime.
3940
*/
40-
trait ThrowingRunnable {
41+
private trait ThrowingRunnable {
4142
def run(): Unit
4243
}
4344

44-
def throwingRunnable(code: => Unit): ThrowingRunnable = {
45+
private def throwingRunnable(code: => Unit): ThrowingRunnable = {
4546
new ThrowingRunnable {
4647
def run(): Unit = code
4748
}
4849
}
4950

51+
def assertThrows[T <: Throwable, U](expectedThrowable: Class[T], code: => U): Unit =
52+
assertThrowsBackport(expectedThrowable, throwingRunnable(code.asInstanceOf[Unit]))
53+
5054
def expectThrows[T <: Throwable, U](expectedThrowable: Class[T], code: => U): T =
51-
expectThrows(expectedThrowable, throwingRunnable(code.asInstanceOf[Unit]))
55+
expectThrowsBackport(expectedThrowable, throwingRunnable(code.asInstanceOf[Unit]))
5256
}

0 commit comments

Comments
 (0)