home | career | drupal | java | mac | mysql | perl | scala | uml | unix

Groovy example source code file (ManagedLinkedlistTest.groovy)

This example Groovy source code file (ManagedLinkedlistTest.groovy) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

groovytestcase, groovytestcase, managedlinkedlist, managedlinkedlist, managedlinkedlisttest, managedlinkedlisttest, referencebundle, referencebundle

The Groovy ManagedLinkedlistTest.groovy source code

package org.codehaus.groovy.util

class ManagedLinkedListTest extends GroovyTestCase{
  
  def list
  
  void setUp() {
    def manager = ReferenceManager.createIdlingManager(null)
    def bundle = new ReferenceBundle(manager, ReferenceType.HARD)
    list = new ManagedLinkedList(bundle)
  }
 
  void testElementAdd() {
    list.add(1)
    def i = 0
    list.each {
      assert it==1
      i++
    }
    assert i ==1 
  }
  
  void testEmptylist() {
    assert list.isEmpty()
  }
  
  void testRemoveinTheMiddle() {
    list.add(1)
    list.add(2)
    list.add(3)
    list.add(4)
    list.add(5)
    def iter = list.iterator()
    while (iter.hasNext()) {
      if (iter.next()==3) iter.remove()
    }
    def val = list.inject(0){value, it-> value+it}
    assert val == 12
  }
  
  void testAddRemove() {
    10.times {
       list.add(it)
       def iter = list.iterator()
       while (iter.hasNext()) {
         if (iter.next()==it) iter.remove()
       }
    }
    assert list.isEmpty()
  }  
}

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy ManagedLinkedlistTest.groovy source code file:

new blog posts

 

Copyright 1998-2014 Alvin Alexander, alvinalexander.com
All Rights Reserved.