Skip to content

Commit

Permalink
Merge pull request #271 from barkhorn/issue-268
Browse files Browse the repository at this point in the history
Issue 268
  • Loading branch information
barkhorn authored Jul 20, 2019
2 parents adfdd51 + 53f1c48 commit a56bfa2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions jvm/src/test/scala/com.paulbutcher.test/mock/JavaMocksTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
22 changes: 10 additions & 12 deletions shared/src/main/scala/org/scalamock/handlers/Handlers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit a56bfa2

Please sign in to comment.