OptionTestUtil.java revision 3195:88a874f33d6d
1/* 2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24package util; 25 26import java.nio.file.Path; 27import java.util.Collection; 28import java.util.HashSet; 29import java.util.Iterator; 30import java.util.List; 31 32import com.sun.tools.sjavac.options.SourceLocation; 33 34 35public class OptionTestUtil { 36 37 public static void checkFilesFound(Collection<String> found, Path... expected) { 38 39 Collection<String> expectedStrs = new HashSet<String>(); 40 for (Path p : expected) 41 expectedStrs.add(p.toString()); 42 43 if (!expectedStrs.containsAll(found)) 44 throw new AssertionError("Expected (" + expectedStrs + ") does not " + 45 "contain all actual (" + found + ")"); 46 47 if (!found.containsAll(expectedStrs)) 48 throw new AssertionError("Actual (" + found + ") does not " + 49 "contain all expected (" + expectedStrs + ")"); 50 } 51 52 public static void assertEquals(List<SourceLocation> expected, List<SourceLocation> actual) { 53 if (expected.size() != actual.size()) 54 throw new AssertionError("Expected locs of length " + expected.size() + " but got something of size " + actual.size()); 55 56 Iterator<SourceLocation> iter1 = expected.iterator(); 57 Iterator<SourceLocation> iter2 = actual.iterator(); 58 59 while (iter1.hasNext()) { 60 SourceLocation sl1 = iter1.next(); 61 SourceLocation sl2 = iter2.next(); 62 63 if (!sl1.getPath().equals(sl2.getPath()) || 64 !sl1.getIncludes().equals(sl2.getIncludes()) || 65 !sl1.getExcludes().equals(sl2.getExcludes())) 66 throw new AssertionError("Expected " + sl1 + " but got " + sl2); 67 } 68 } 69 70 public static void assertEquals(Object expected, Object actual) { 71 if (!expected.equals(actual)) 72 throw new AssertionError("Expected " + expected + " but got " + actual); 73 } 74 75} 76