# JavaListifyCmd.test --
#
#	Tests the JavaListifyCmd class.
#

package require TTXN
  # package under test is JBlend 2.0
package require JBlend 2.0



Name: JavaListifyCmd-1.1
Description: {list an empty collection}
Test: {
    set L [java::listify [java::new java.util.Vector]]
    llength $L  ;# result is the empty list
}
Expected: 0

Name: JavaListifyCmd-1.2
Description: {List a null object}
Test: {
    set L [java::listify [java::null]]
    llength $L  ;# result is the empty list
}
Expected: 0

Name: JavaListifyCmd-1.3
Description: {list a collection with one elem}
Test: {
    set jColl [java::new java.util.Vector]
    $jColl add 123
    set L [java::listify $jColl]
    unset jColl
    lindex $L 0
}
Expected: 123

Name: JavaListifyCmd-1.4
Description: {list a collection with 3 elems}
Test: {
    set jColl [java::new java.util.Vector]
    $jColl add 123
    $jColl add 456
    $jColl add 789    
    set L [java::listify $jColl]
    unset jColl
    set L
}
Expected: {123 456 789}

Name: JavaListifyCmd-1.4.1
Description: {list a collection with 3 doubles}
Test: {
    set jColl [java::new java.util.Vector]
    $jColl add 1.23
    $jColl add 4.56
    $jColl add 7.89    
    set L [java::listify $jColl]
    unset jColl
    set L
}
Expected: {1.23 4.56 7.89}

Name: JavaListifyCmd-1.5
Description: {list a collection with 3 elems - middle elem is null}
Test: {
    set jColl [java::new java.util.Vector]
    $jColl add 123
    $jColl add [java::null]
    $jColl add 789    
    set L [java::listify $jColl]
    unset jColl
    set L
}
Expected: {123 {} 789}

 
Name: JavaListifyCmd-1.6
Description: {list a collection with 3 elems - middle elem is null}
Test: {
 set jColl [java::new java.util.Vector]
 $jColl add [java::new java.util.GregorianCalendar] ;# now
 $jColl add [java::null]
 $jColl add [java::new java.util.GregorianCalendar 2001 10 13]
    set L [java::listify $jColl]
    unset jColl
    set L
}
Expected: glob {java* {} java*}

Name: JavaListifyCmd-1.7
Description: {list a collection with 3 elems - middle elem is null - and force elem conversion}
Test: {
 set jColl [java::new java.util.Vector]
 $jColl add [java::new java.util.GregorianCalendar] ;# now
 $jColl add [java::null]
 $jColl add [java::new java.util.GregorianCalendar 2001 10 13]
    set L [java::listify {java.util.Calendar} $jColl]
    unset jColl
    java::info class [lindex $L end]
}
Expected: {java.util.Calendar}


Name: JavaListifyCmd-1.8
Description: {list (-noconvert) - different classes and 'primitives'}
Test: {
 set jColl [java::new java.util.Vector]
 $jColl add [java::new java.util.GregorianCalendar] ;# now
 $jColl add [java::null]
 $jColl add 1999.99
 $jColl add "Hello World"
    set L [java::listify -noconvert $jColl]
    unset jColl
    set L
}
Expected: glob {java* java0x0 java* java*}

Name: JavaListifyCmd-1.9
Description: {list a collection -implicit conversion - different classes and 'primitives'}
Test: {
 set jColl [java::new java.util.Vector]
 $jColl add [java::new java.util.GregorianCalendar] ;# now
 $jColl add [java::null]
 $jColl add 1999.99
 $jColl add [java::new String "Hello Java"]
 $jColl add "Hello World"
    set L [java::listify $jColl]
    unset jColl
    set L
}
Expected: glob {java* {} 1999.99 {Hello Java} {Hello World}}


Name: JavaListifyCmd-NEG.1.1
Description: {call method without required params}
Test: {
    set res [java::listify]
}
Expected: error glob {wrong # args: should be "java::listify *"}

Name: JavaListifyCmd-NEG.1.2
Description: {call method with extra parameters}
Test: {
    set res [java::listify aaa bbb ccc]
}
Expected: error glob {wrong # args: should be "java::listify *"}

Name: JavaListifyCmd-NEG.1.3
Description: {call method with an explicit (non-existent) class}
Test: {
    set res [java::listify xxx.yyy.zzz  someObj]
}
Expected: error glob {unknown class *}

Name: JavaListifyCmd-NEG.1.4
Description: {call method with a non-existent collection}
Test: {
    set res [java::listify  badObj]
}
Expected: error glob {unknown java object "*"}


Name: JavaListifyCmd-3.0
Description: {list an enumeration}
Test: {
    set jColl [java::new java.util.Vector]
    $jColl add 123
    $jColl add [java::null]
    $jColl add 789
     # transform in an enumeration ..
    set jEnum [java::call java.util.Collections enumeration $jColl]   
    set L [java::listify $jEnum]}
Expected: {123 {} 789}





# === cleanup ========================================
::tcltest::cleanupTests
return
