Skip to content

Commit 46bdaab

Browse files
authored
upgrade mockito and scalafmt (#435)
* upgrade mockito and scalafmt * upgrade minor version
1 parent 5e70319 commit 46bdaab

39 files changed

+274
-413
lines changed

.scalafmt.conf

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
style = defaultWithAlign
22

3-
docstrings = JavaDoc
3+
runner.dialect = scala213
4+
docstrings.style = asterisk
45
maxColumn = 180
56
rewrite.rules = [RedundantBraces, RedundantParens, SortImports]
67
spaces.inImportCurlyBraces = true
7-
indentOperator = spray
8+
indentOperator.preset = spray
89
unindentTopLevelOperators = true
910

10-
version=2.7.5
11+
version=3.3.1
1112

common/src/main/scala/org/mockito/MockitoAPI.scala

+39-63
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import scala.reflect.ClassTag
3232
import scala.reflect.runtime.universe.WeakTypeTag
3333

3434
private[mockito] trait ScalacticSerialisableHack {
35-
//Hack until Equality can be made serialisable
35+
// Hack until Equality can be made serialisable
3636
implicit def mockitoSerialisableEquality[T]: Equality[T] = serialisableEquality[T]
3737
}
3838

@@ -58,22 +58,19 @@ private[mockito] trait MockCreator {
5858
private[mockito] trait DoSomething {
5959

6060
/**
61-
* Delegates the call to <code>Mockito.doReturn(toBeReturned, toBeReturnedNext)</code>
62-
* but fixes the following compiler issue that happens because the overloaded vararg on the Java side
61+
* Delegates the call to <code>Mockito.doReturn(toBeReturned, toBeReturnedNext)</code> but fixes the following compiler issue that happens because the overloaded vararg on the
62+
* Java side
6363
*
64-
* {{{Error:(33, 25) ambiguous reference to overloaded definition,
65-
* both method doReturn in class Mockito of type (x$1: Any, x$2: Object*)org.mockito.stubbing.Stubber
66-
* and method doReturn in class Mockito of type (x$1: Any)org.mockito.stubbing.Stubber
67-
* match argument types (`Type`)}}}
64+
* {{{Error:(33, 25) ambiguous reference to overloaded definition, both method doReturn in class Mockito of type (x$1: Any, x$2: Object*)org.mockito.stubbing.Stubber and method
65+
* doReturn in class Mockito of type (x$1: Any)org.mockito.stubbing.Stubber match argument types (`Type`)}}}
6866
*/
6967
def doReturn[T: ValueClassExtractor](toBeReturned: T, toBeReturnedNext: T*): Stubber =
7068
toBeReturnedNext.foldLeft(Mockito.doAnswer(ScalaReturns(toBeReturned))) { case (s, v) =>
7169
s.doAnswer(ScalaReturns(v))
7270
}
7371

7472
/**
75-
* Delegates to <code>Mockito.doThrow</code>, it's only here so we expose all the Mockito API
76-
* on a single place
73+
* Delegates to <code>Mockito.doThrow</code>, it's only here so we expose all the Mockito API on a single place
7774
*/
7875
def doThrow(toBeThrown: Throwable*): Stubber = {
7976
val stubber = Mockito.MOCKITO_CORE.stubber
@@ -82,8 +79,7 @@ private[mockito] trait DoSomething {
8279
}
8380

8481
/**
85-
* Delegates to <code>Mockito.doThrow(type: Class[T])</code>
86-
* It provides a nicer API as you can, for instance, do doThrow[Throwable] instead of doThrow(classOf[Throwable])
82+
* Delegates to <code>Mockito.doThrow(type: Class[T])</code> It provides a nicer API as you can, for instance, do doThrow[Throwable] instead of doThrow(classOf[Throwable])
8783
*/
8884
def doThrow[T <: Throwable: ClassTag]: Stubber = Mockito.doAnswer(ScalaThrowsException[T])
8985

@@ -458,52 +454,40 @@ private[mockito] trait MockitoEnhancer extends MockCreator {
458454
implicit val invocationOps: InvocationOnMock => InvocationOnMockOps = InvocationOps
459455

460456
/**
461-
* Delegates to <code>Mockito.mock(type: Class[T])</code>
462-
* It provides a nicer API as you can, for instance, do <code>mock[MyClass]</code>
463-
* instead of <code>mock(classOf[MyClass])</code>
457+
* Delegates to <code>Mockito.mock(type: Class[T])</code> It provides a nicer API as you can, for instance, do <code>mock[MyClass]</code> instead of
458+
* <code>mock(classOf[MyClass])</code>
464459
*
465-
* It also pre-stub the mock so the compiler-generated methods that provide the values for the default arguments
466-
* are called, ie:
467-
* given <code>def iHaveSomeDefaultArguments(noDefault: String, default: String = "default value")</code>
460+
* It also pre-stub the mock so the compiler-generated methods that provide the values for the default arguments are called, ie: given <code>def
461+
* iHaveSomeDefaultArguments(noDefault: String, default: String = "default value")</code>
468462
*
469-
* without this fix, if you call it as <code>iHaveSomeDefaultArguments("I'm not gonna pass the second argument")</code>
470-
* then you could have not verified it like
471-
* <code>verify(aMock).iHaveSomeDefaultArguments("I'm not gonna pass the second argument", "default value")</code>
472-
* as the value for the second parameter would have been null...
463+
* without this fix, if you call it as <code>iHaveSomeDefaultArguments("I'm not gonna pass the second argument")</code> then you could have not verified it like
464+
* <code>verify(aMock).iHaveSomeDefaultArguments("I'm not gonna pass the second argument", "default value")</code> as the value for the second parameter would have been null...
473465
*/
474466
override def mock[T <: AnyRef: ClassTag: WeakTypeTag](implicit defaultAnswer: DefaultAnswer, $pt: Prettifier): T =
475467
createMock(withSettings)
476468

477469
/**
478-
* Delegates to <code>Mockito.mock(type: Class[T], defaultAnswer: Answer[_])</code>
479-
* It provides a nicer API as you can, for instance, do <code>mock[MyClass](defaultAnswer)</code>
470+
* Delegates to <code>Mockito.mock(type: Class[T], defaultAnswer: Answer[_])</code> It provides a nicer API as you can, for instance, do <code>mock[MyClass](defaultAnswer)</code>
480471
* instead of <code>mock(classOf[MyClass], defaultAnswer)</code>
481472
*
482-
* It also pre-stub the mock so the compiler-generated methods that provide the values for the default arguments
483-
* are called, ie:
484-
* given <code>def iHaveSomeDefaultArguments(noDefault: String, default: String = "default value")</code>
473+
* It also pre-stub the mock so the compiler-generated methods that provide the values for the default arguments are called, ie: given <code>def
474+
* iHaveSomeDefaultArguments(noDefault: String, default: String = "default value")</code>
485475
*
486-
* without this fix, if you call it as <code>iHaveSomeDefaultArguments("I'm not gonna pass the second argument")</code>
487-
* then you could have not verified it like
488-
* <code>verify(aMock).iHaveSomeDefaultArguments("I'm not gonna pass the second argument", "default value")</code>
489-
* as the value for the second parameter would have been null...
476+
* without this fix, if you call it as <code>iHaveSomeDefaultArguments("I'm not gonna pass the second argument")</code> then you could have not verified it like
477+
* <code>verify(aMock).iHaveSomeDefaultArguments("I'm not gonna pass the second argument", "default value")</code> as the value for the second parameter would have been null...
490478
*/
491479
override def mock[T <: AnyRef: ClassTag: WeakTypeTag](defaultAnswer: DefaultAnswer)(implicit $pt: Prettifier): T =
492480
createMock(withSettings(defaultAnswer))
493481

494482
/**
495-
* Delegates to <code>Mockito.mock(type: Class[T], mockSettings: MockSettings)</code>
496-
* It provides a nicer API as you can, for instance, do <code>mock[MyClass](mockSettings)</code>
497-
* instead of <code>mock(classOf[MyClass], mockSettings)</code>
483+
* Delegates to <code>Mockito.mock(type: Class[T], mockSettings: MockSettings)</code> It provides a nicer API as you can, for instance, do
484+
* <code>mock[MyClass](mockSettings)</code> instead of <code>mock(classOf[MyClass], mockSettings)</code>
498485
*
499-
* It also pre-stub the mock so the compiler-generated methods that provide the values for the default arguments
500-
* are called, ie:
501-
* given <code>def iHaveSomeDefaultArguments(noDefault: String, default: String = "default value")</code>
486+
* It also pre-stub the mock so the compiler-generated methods that provide the values for the default arguments are called, ie: given <code>def
487+
* iHaveSomeDefaultArguments(noDefault: String, default: String = "default value")</code>
502488
*
503-
* without this fix, if you call it as <code>iHaveSomeDefaultArguments("I'm not gonna pass the second argument")</code>
504-
* then you could have not verified it like
505-
* <code>verify(aMock).iHaveSomeDefaultArguments("I'm not gonna pass the second argument", "default value")</code>
506-
* as the value for the second parameter would have been null...
489+
* without this fix, if you call it as <code>iHaveSomeDefaultArguments("I'm not gonna pass the second argument")</code> then you could have not verified it like
490+
* <code>verify(aMock).iHaveSomeDefaultArguments("I'm not gonna pass the second argument", "default value")</code> as the value for the second parameter would have been null...
507491
*/
508492
override def mock[T <: AnyRef: ClassTag: WeakTypeTag](mockSettings: MockSettings)(implicit $pt: Prettifier): T =
509493
createMock(mockSettings)
@@ -545,18 +529,14 @@ private[mockito] trait MockitoEnhancer extends MockCreator {
545529
}
546530

547531
/**
548-
* Delegates to <code>Mockito.mock(type: Class[T], name: String)</code>
549-
* It provides a nicer API as you can, for instance, do <code>mock[MyClass](name)</code>
550-
* instead of <code>mock(classOf[MyClass], name)</code>
532+
* Delegates to <code>Mockito.mock(type: Class[T], name: String)</code> It provides a nicer API as you can, for instance, do <code>mock[MyClass](name)</code> instead of
533+
* <code>mock(classOf[MyClass], name)</code>
551534
*
552-
* It also pre-stub the mock so the compiler-generated methods that provide the values for the default arguments
553-
* are called, ie:
554-
* given <code>def iHaveSomeDefaultArguments(noDefault: String, default: String = "default value")</code>
535+
* It also pre-stub the mock so the compiler-generated methods that provide the values for the default arguments are called, ie: given <code>def
536+
* iHaveSomeDefaultArguments(noDefault: String, default: String = "default value")</code>
555537
*
556-
* without this fix, if you call it as <code>iHaveSomeDefaultArguments("I'm not gonna pass the second argument")</code>
557-
* then you could have not verified it like
558-
* <code>verify(aMock).iHaveSomeDefaultArguments("I'm not gonna pass the second argument", "default value")</code>
559-
* as the value for the second parameter would have been null...
538+
* without this fix, if you call it as <code>iHaveSomeDefaultArguments("I'm not gonna pass the second argument")</code> then you could have not verified it like
539+
* <code>verify(aMock).iHaveSomeDefaultArguments("I'm not gonna pass the second argument", "default value")</code> as the value for the second parameter would have been null...
560540
*/
561541
override def mock[T <: AnyRef: ClassTag: WeakTypeTag](name: String)(implicit defaultAnswer: DefaultAnswer, $pt: Prettifier): T =
562542
mock(withSettings.name(name))
@@ -568,8 +548,7 @@ private[mockito] trait MockitoEnhancer extends MockCreator {
568548
}
569549

570550
/**
571-
* Delegates to <code>Mockito.reset(T... mocks)</code>, but restores the default stubs that
572-
* deal with default argument values
551+
* Delegates to <code>Mockito.reset(T... mocks)</code>, but restores the default stubs that deal with default argument values
573552
*/
574553
def reset(mocks: AnyRef*)(implicit $pt: Prettifier): Unit = {
575554
val mp = mockingProgress()
@@ -592,8 +571,7 @@ private[mockito] trait MockitoEnhancer extends MockCreator {
592571
def mockingDetails(toInspect: AnyRef): MockingDetails = Mockito.mockingDetails(toInspect)
593572

594573
/**
595-
* Delegates to <code>Mockito.verifyNoMoreInteractions(Object... mocks)</code>, but ignores the default stubs that
596-
* deal with default argument values
574+
* Delegates to <code>Mockito.verifyNoMoreInteractions(Object... mocks)</code>, but ignores the default stubs that deal with default argument values
597575
*/
598576
def verifyNoMoreInteractions(mocks: AnyRef*): Unit = {
599577
def ignoreDefaultArguments(m: AnyRef): Unit =
@@ -618,8 +596,7 @@ private[mockito] trait MockitoEnhancer extends MockCreator {
618596
def ignoreStubs(mocks: AnyRef*): Array[AnyRef] = Mockito.ignoreStubs(mocks: _*)
619597

620598
/**
621-
* Creates a "spy" in a way that supports lambdas and anonymous classes as they don't work with the standard spy as
622-
* they are created as final classes by the compiler
599+
* Creates a "spy" in a way that supports lambdas and anonymous classes as they don't work with the standard spy as they are created as final classes by the compiler
623600
*/
624601
def spyLambda[T <: AnyRef: ClassTag](realObj: T): T = Mockito.mock(clazz, AdditionalAnswers.delegatesTo(realObj))
625602

@@ -632,9 +609,8 @@ private[mockito] trait MockitoEnhancer extends MockCreator {
632609
/**
633610
* Spies the specified object only for the context of the block
634611
*
635-
* Automatically pulls in [[org.mockito.LeniencySettings#strictStubs strict stubbing]] behaviour via implicits.
636-
* To override this default (strict) behaviour, bring lenient settings into implicit scope;
637-
* see [[org.mockito.leniency]] for details
612+
* Automatically pulls in [[org.mockito.LeniencySettings#strictStubs strict stubbing]] behaviour via implicits. To override this default (strict) behaviour, bring lenient
613+
* settings into implicit scope; see [[org.mockito.leniency]] for details
638614
*/
639615
def withObjectSpied[O <: AnyRef: ClassTag](block: => Any)(implicit leniency: LeniencySettings, $pt: Prettifier): Unit = {
640616
val settings = leniency(Mockito.withSettings().defaultAnswer(CALLS_REAL_METHODS))
@@ -726,10 +702,10 @@ private[mockito] trait Verifications {
726702
*
727703
* The idea is based on org.scalatest.mockito.MockitoSugar but it adds 100% of the Mockito API
728704
*
729-
* It also solve problems like overloaded varargs calls to Java code and pre-stub the mocks so the default arguments
730-
* in the method parameters work as expected
705+
* It also solve problems like overloaded varargs calls to Java code and pre-stub the mocks so the default arguments in the method parameters work as expected
731706
*
732-
* @author Bruno Bonanno
707+
* @author
708+
* Bruno Bonanno
733709
*/
734710
private[mockito] trait Rest extends MockitoEnhancer with DoSomething with Verifications {
735711

@@ -746,7 +722,7 @@ private[mockito] trait Rest extends MockitoEnhancer with DoSomething with Verifi
746722
/**
747723
* Delegates to <code>Mockito.verifyZeroInteractions()</code>, it's only here to expose the full Mockito API
748724
*/
749-
def verifyZeroInteractions(mocks: AnyRef*): Unit = Mockito.verifyZeroInteractions(mocks: _*)
725+
def verifyZeroInteractions(mocks: AnyRef*): Unit = Mockito.verifyNoInteractions(mocks: _*)
750726

751727
/**
752728
* Delegates to <code>Mockito.inOrder()</code>, it's only here to expose the full Mockito API

common/src/main/scala/org/mockito/internal/handler/ScalaMockHandler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class ScalaMockHandler[T](mockSettings: MockCreationSettings[T], methodsToProces
7676
}
7777
.getOrElse(args)
7878

79-
//For some border cases, we can't extract the varargs in the nice way, so we try the brute force one
79+
// For some border cases, we can't extract the varargs in the nice way, so we try the brute force one
8080
if (methodsToProcess.isEmpty || args.length != transformed.length) transformed
8181
else unwrapVarargs(transformed)
8282
}

common/src/main/scala/org/mockito/internal/invocation/ScalaInvocation.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ class ScalaInvocation(
5353
other match {
5454
case that: ScalaInvocation =>
5555
super.equals(that) &&
56-
getMock == that.getMock &&
57-
mockitoMethod == that.mockitoMethod &&
58-
(arguments sameElements that.arguments)
56+
getMock == that.getMock &&
57+
mockitoMethod == that.mockitoMethod &&
58+
(arguments sameElements that.arguments)
5959
case _ => false
6060
}
6161
override def hashCode(): Int = {

0 commit comments

Comments
 (0)