diff --git a/.travis.yml b/.travis.yml index e20d06c4..641e852d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ cache: # - sudo chmod +x /usr/local/bin/sbt after_success: - - '[[ $TRAVIS_BRANCH == "master" ]] && [[ $TRAVIS_JDK_VERSION == "openjdk11" ]] && { sbt ++$TRAVIS_SCALA_VERSION publish; };' + - '[[ $TRAVIS_BRANCH == "master" ]] && [[ $TRAVIS_JDK_VERSION == "openjdk11" ]] && [[ $SONATYPE_USERNAME != "" ]] && { sbt ++$TRAVIS_SCALA_VERSION publish; };' env: global: diff --git a/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala b/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala index 1921da0c..3ab3bbeb 100644 --- a/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala +++ b/jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala @@ -35,15 +35,15 @@ class JavaMocksTest extends IsolatedSpec { it should "mock classes with bridged methods" in { val m = mock[JavaClassWithBridgeMethod] - (m.compare _).expects(new Integer(5)).returning(1) - (m.compare _).expects(new Integer(6)).returning(2) + (m.compare _).expects(Integer.valueOf(5)).returning(1) + (m.compare _).expects(Integer.valueOf(6)).returning(2) def useBridgeMethod[T](gen: JavaGenericInterface[T], x: T) = { gen.compare(x) } - assertResult(1) { m.compare(new Integer(5)) } // calls: int compare(Integer) - assertResult(2) { useBridgeMethod(m, new Integer(6)) } // calls: int compare(Object) + assertResult(1) { m.compare(Integer.valueOf(5)) } // calls: int compare(Integer) + assertResult(2) { useBridgeMethod(m, Integer.valueOf(6)) } // calls: int compare(Object) } //! TODO - this is going to have to wait for macro types for a proper solution @@ -87,7 +87,7 @@ class JavaMocksTest extends IsolatedSpec { it should "mock a Java class with an overloaded method (the same param count)" in { // test for issue #73 val m = mock[JavaClassWithOverloadedMethod] (m.overloadedSameParamCount(_: String)).expects("one").returning("first") - (m.overloadedSameParamCount(_: Integer)).expects(new Integer(2)).returning(2) + (m.overloadedSameParamCount(_: Integer)).expects(Integer.valueOf(2)).returning(2) m.overloadedSameParamCount("one") shouldBe "first" m.overloadedSameParamCount(2) shouldBe 2 diff --git a/shared/src/main/scala/org/scalamock/handlers/Handlers.scala b/shared/src/main/scala/org/scalamock/handlers/Handlers.scala index 64b47ab3..bc5926ff 100644 --- a/shared/src/main/scala/org/scalamock/handlers/Handlers.scala +++ b/shared/src/main/scala/org/scalamock/handlers/Handlers.scala @@ -23,19 +23,17 @@ package org.scalamock.handlers import scala.collection.mutable.ListBuffer private[scalamock] abstract class Handlers extends Handler { + + def add(handler: Handler): Unit = handlers += handler - def add(handler: Handler): Unit = { - handlers += handler - } - - def isSatisfied = handlers forall (_.isSatisfied) - - override def toString = - handlers.map { h => - h.toString.lines.toArray.map { l => " " + l} - }.flatten.mkString(s"$prefix {\n", "\n", "\n}") - - protected val handlers = new ListBuffer[Handler] + def isSatisfied: Boolean = handlers forall (_.isSatisfied) + + override def toString = handlers.flatMap { h => + // see https://github.com/scala/bug/issues/11125. linesIterator would be better but we crossbuild with 2.11 + scala.Predef.augmentString(h.toString).lines.toArray.map { l => " " + l } + }.mkString(s"$prefix {\n", "\n", "\n}") + protected var handlers = new ListBuffer[Handler] + protected val prefix: String }