Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should Cookies's equality be based on its inner Cookies? #11666

Open
y-yu opened this issue Feb 9, 2023 · 0 comments
Open

Should Cookies's equality be based on its inner Cookies? #11666

y-yu opened this issue Feb 9, 2023 · 0 comments

Comments

@y-yu
Copy link
Contributor

y-yu commented Feb 9, 2023

  • It's inconvenient for mocking like:
    val fakeCookies = Cookies(Nil)
    
    Mockito.when(userIdFromCookieService.get(fakeCookies))
       .thenReturn(UserId("foobar"))
  • So would it be better to determine if two Cookies are the same or not based on its contents? 🤔

Play Version

2.8.19

API

play.api.mvc.Cookies

Operating System

  • macOS

JDK

  • OpenJDK 64-Bit Server VM, Java 11.0.18

Actual Behavior

scala> play.api.mvc.Cookies.apply(Nil)
val res0: play.api.mvc.Cookies = Iterable()

scala> play.api.mvc.Cookies.apply(Nil)
val res1: play.api.mvc.Cookies = Iterable()

scala> res0 == res1
val res2: Boolean = false

Expected Behavior

res0 == res1 // true

P.S.

In Mokito, here is a work around:

def eqCookies(expected: Cookies): Cookies = {
  val matcher: ArgumentMatcher[Cookies] = (argument: Cookies) => {
    (argument == null && expected == null) ||
    (argument != null && expected != null && argument.toSeq == expected.toSeq)
  }
  ThreadSafeMockingProgress
    .mockingProgress()
    .getArgumentMatcherStorage
    .reportMatcher(matcher)
  null
}
val fakeCookies = Cookies(Nil)

Mockito.when(userIdFromCookieService.get(eqCookies(fakeCookies)))
   .thenReturn(UserId("foobar"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant