From f9879036c4ccaebd41e3315e017fddb07c45f000 Mon Sep 17 00:00:00 2001
From: Travis Brown <travisrobertbrown@gmail.com>
Date: Thu, 27 Feb 2020 16:03:12 +0100
Subject: [PATCH] Re-encode relationships to avoid implicit conversion
 functions (#3323)

---
 .../cats/tests/NonEmptyLazyListSuite.scala           |  5 +++--
 .../test/scala/cats/tests/NonEmptyChainSuite.scala   |  5 +++--
 .../scala/cats/tests/NonEmptyCollectionSuite.scala   | 12 +++++++-----
 .../test/scala/cats/tests/NonEmptyListSuite.scala    |  5 +++--
 .../test/scala/cats/tests/NonEmptyVectorSuite.scala  |  5 +++--
 5 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/tests/src/test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala b/tests/src/test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala
index 68666023ed..48ba017f4f 100644
--- a/tests/src/test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala
+++ b/tests/src/test/scala-2.13+/cats/tests/NonEmptyLazyListSuite.scala
@@ -7,8 +7,9 @@ import cats.laws.discipline.{AlignTests, BimonadTests, NonEmptyTraverseTests, Se
 import cats.laws.discipline.arbitrary._
 
 class NonEmptyLazyListSuite extends NonEmptyCollectionSuite[LazyList, NonEmptyLazyList, NonEmptyLazyListOps] {
-  def toList[A](value: NonEmptyLazyList[A]): List[A] = value.toList
-  def underlyingToList[A](underlying: LazyList[A]): List[A] = underlying.toList
+  protected def toList[A](value: NonEmptyLazyList[A]): List[A] = value.toList
+  protected def underlyingToList[A](underlying: LazyList[A]): List[A] = underlying.toList
+  protected def toNonEmptyCollection[A](nea: NonEmptyLazyList[A]): NonEmptyLazyListOps[A] = nea
 
   checkAll("NonEmptyLazyList[Int]", SemigroupTests[NonEmptyLazyList[Int]].semigroup)
   checkAll(s"Semigroup[NonEmptyLazyList]", SerializableTests.serializable(Semigroup[NonEmptyLazyList[Int]]))
diff --git a/tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala
index b4910c49a3..b269401d0d 100644
--- a/tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala
+++ b/tests/src/test/scala/cats/tests/NonEmptyChainSuite.scala
@@ -7,8 +7,9 @@ import cats.laws.discipline.{AlignTests, BimonadTests, NonEmptyTraverseTests, Se
 import cats.laws.discipline.arbitrary._
 
 class NonEmptyChainSuite extends NonEmptyCollectionSuite[Chain, NonEmptyChain, NonEmptyChainOps] {
-  def toList[A](value: NonEmptyChain[A]): List[A] = value.toChain.toList
-  def underlyingToList[A](underlying: Chain[A]): List[A] = underlying.toList
+  protected def toList[A](value: NonEmptyChain[A]): List[A] = value.toChain.toList
+  protected def underlyingToList[A](underlying: Chain[A]): List[A] = underlying.toList
+  protected def toNonEmptyCollection[A](nea: NonEmptyChain[A]): NonEmptyChainOps[A] = nea
 
   checkAll("NonEmptyChain[Int]", SemigroupKTests[NonEmptyChain].semigroupK[Int])
   checkAll("SemigroupK[NonEmptyChain]", SerializableTests.serializable(SemigroupK[NonEmptyChain]))
diff --git a/tests/src/test/scala/cats/tests/NonEmptyCollectionSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyCollectionSuite.scala
index 5d8feecb99..6433a542ce 100644
--- a/tests/src/test/scala/cats/tests/NonEmptyCollectionSuite.scala
+++ b/tests/src/test/scala/cats/tests/NonEmptyCollectionSuite.scala
@@ -5,12 +5,14 @@ import org.scalacheck.Arbitrary
 
 abstract class NonEmptyCollectionSuite[U[+_], NE[+_], NEC[x] <: NonEmptyCollection[x, U, NE]](
   implicit arbitraryU: Arbitrary[U[Int]],
-  arbitraryNE: Arbitrary[NE[Int]],
-  ev: NE[Int] => NEC[Int],
-  evPair: NE[(Int, Int)] => NEC[(Int, Int)]
+  arbitraryNE: Arbitrary[NE[Int]]
 ) extends CatsSuite {
-  def toList[A](value: NE[A]): List[A]
-  def underlyingToList[A](underlying: U[A]): List[A]
+  protected def toList[A](value: NE[A]): List[A]
+  protected def underlyingToList[A](underlying: U[A]): List[A]
+
+  // Necessary because of the non-inheritance-based encoding of some non-empty collections.
+  protected def toNonEmptyCollection[A](nea: NE[A]): NEC[A]
+  implicit private def convertToNonEmptyCollection[A](nea: NE[A]): NEC[A] = toNonEmptyCollection(nea)
 
   test("head is consistent with iterator.toList.head") {
     forAll { (is: NE[Int]) =>
diff --git a/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala
index 8e5926129f..8cc6b9c438 100644
--- a/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala
+++ b/tests/src/test/scala/cats/tests/NonEmptyListSuite.scala
@@ -19,8 +19,9 @@ import scala.collection.immutable.SortedMap
 import scala.collection.immutable.SortedSet
 
 class NonEmptyListSuite extends NonEmptyCollectionSuite[List, NonEmptyList, NonEmptyList] {
-  def toList[A](value: NonEmptyList[A]): List[A] = value.toList
-  def underlyingToList[A](underlying: List[A]): List[A] = underlying
+  protected def toList[A](value: NonEmptyList[A]): List[A] = value.toList
+  protected def underlyingToList[A](underlying: List[A]): List[A] = underlying
+  protected def toNonEmptyCollection[A](nea: NonEmptyList[A]): NonEmptyList[A] = nea
 
   // Lots of collections here.. telling ScalaCheck to calm down a bit
   implicit override val generatorDrivenConfig: PropertyCheckConfiguration =
diff --git a/tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala b/tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala
index 604d2e9ea1..8cd4489437 100644
--- a/tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala
+++ b/tests/src/test/scala/cats/tests/NonEmptyVectorSuite.scala
@@ -22,8 +22,9 @@ import cats.platform.Platform
 import scala.util.Properties
 
 class NonEmptyVectorSuite extends NonEmptyCollectionSuite[Vector, NonEmptyVector, NonEmptyVector] {
-  def toList[A](value: NonEmptyVector[A]): List[A] = value.toList
-  def underlyingToList[A](underlying: Vector[A]): List[A] = underlying.toList
+  protected def toList[A](value: NonEmptyVector[A]): List[A] = value.toList
+  protected def underlyingToList[A](underlying: Vector[A]): List[A] = underlying.toList
+  protected def toNonEmptyCollection[A](nea: NonEmptyVector[A]): NonEmptyVector[A] = nea
 
   // Lots of collections here.. telling ScalaCheck to calm down a bit
   implicit override val generatorDrivenConfig: PropertyCheckConfiguration =