rt/emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 26 Feb 2013 16:54:16 +0100
changeset 772 d382dacfd73f
parent 599 emul/compact/src/test/java/org/apidesign/bck2brwsr/compact/tck/CollectionsTest.java@d0f57d3ea898
child 1394 66b5956ee49d
permissions -rw-r--r--
Moving modules around so the runtime is under one master pom and can be built without building other modules that are in the repository
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. Look for COPYING file in the top folder.
    16  * If not, see http://opensource.org/licenses/GPL-2.0.
    17  */
    18 package org.apidesign.bck2brwsr.compact.tck;
    19 
    20 import java.util.ArrayList;
    21 import java.util.Arrays;
    22 import java.util.Collection;
    23 import java.util.Comparator;
    24 import java.util.HashMap;
    25 import java.util.HashSet;
    26 import java.util.List;
    27 import java.util.Map;
    28 import java.util.Map.Entry;
    29 import java.util.Vector;
    30 import org.apidesign.bck2brwsr.vmtest.Compare;
    31 import org.apidesign.bck2brwsr.vmtest.VMTest;
    32 import org.testng.annotations.Factory;
    33 
    34 /**
    35  *
    36  * @author Jaroslav Tulach <jtulach@netbeans.org>
    37  */
    38 public class CollectionsTest {
    39     @Compare public String sortStringsInArray() {
    40         List<String> list = new ArrayList<>();
    41         list.add("one");
    42         list.add("two");
    43         list.add("three");
    44         list.add("four");
    45         list.add("five");
    46         list.add("six");
    47         list.add("seven");
    48         list.add("eight");
    49         list.add("nine");
    50         list.add("ten");
    51         
    52         String[] arr = list.toArray(new String[list.size()]);
    53         Arrays.sort(arr);
    54         
    55         return Arrays.asList(arr).toString();
    56     }
    57     
    58     @Compare public String sortStringsInHashSet() {
    59         Collection<String> list = new HashSet<>();
    60         list.add("one");
    61         list.add("two");
    62         list.add("three");
    63         list.add("four");
    64         list.add("five");
    65         list.add("six");
    66         list.add("seven");
    67         list.add("eight");
    68         list.add("nine");
    69         list.add("ten");
    70         
    71         String[] arr = list.toArray(new String[0]);
    72         Arrays.sort(arr);
    73         
    74         return Arrays.asList(arr).toString();
    75     }
    76 
    77     @SuppressWarnings("unchecked")
    78     @Compare public String sortStringsInHashMapWithComparator() {
    79         class C implements Comparator<Map.Entry<String,Integer>> {
    80             public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
    81                 return o1.getKey().compareTo(o2.getKey());
    82             }
    83         }
    84         
    85         Map<String,Integer> map = new HashMap<>();
    86         map.put("one", 1);
    87         map.put("two", 2);
    88         map.put("three", 3);
    89         map.put("four", 4);
    90         map.put("five", 5);
    91         map.put("six", 6);
    92         map.put("seven", 7);
    93         map.put("eight", 8);
    94         map.put("nine", 9);
    95         map.put("ten", 10);
    96         
    97         List<Entry<String,Integer>> arr = new Vector<>();
    98         arr.addAll(map.entrySet());
    99         return arr.toString();
   100     }
   101     
   102     @Factory
   103     public static Object[] create() {
   104         return VMTest.create(CollectionsTest.class);
   105     }
   106     
   107 }