samples/effectivelist/test/org/apidesign/effectivelist/ListMixinTest.scala
author Jaroslav Tulach <jtulach@netbeans.org>
Sun, 02 Sep 2012 22:00:13 +0200
changeset 403 ebe08056c60c
child 404 dc0d785c5b5d
permissions -rw-r--r--
Identifying code snippets to be used on my blog
     1 package org.apidesign.effectivelist
     2 
     3 import org.junit._
     4 import Assert._
     5 
     6 // BEGIN: effectivelist.point
     7 class Point(val x: Int, val y : Int);
     8 // END: effectivelist.point
     9 
    10 class ListMixinTest {
    11   // BEGIN: effectivelist.convert
    12   class ListablePoint(x: Int, y: Int) extends Point(x,y) with Listable[ListablePoint] {
    13     def this(r : Point) = this(r.x, r.y)
    14   }
    15   implicit def toList(p : Point) : ListablePoint = new ListablePoint(p)
    16 
    17   @Test def useThePlainOldPointInList : Unit = {
    18     val list = new List[ListablePoint]
    19     list.add(new Point(10, 20))
    20     assertEquals("One element", 1, list.size)
    21     assertEquals("X is 10", 10, list.get(0).x)
    22     assertEquals("y is 20", 20, list.get(0).y)
    23   }
    24   // END: effectivelist.convert
    25 
    26 }