Skip to content

Commit 9d00beb

Browse files
committed
CSV-69 Utility methods for comparing results
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/csv/trunk@1306828 13f79535-47bb-0310-9956-ffa450edef68
1 parent 8462234 commit 9d00beb

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package org.apache.commons.csv;
20+
21+
import java.util.List;
22+
23+
import org.junit.Assert;
24+
25+
/**
26+
* Utility methods for test cases
27+
*/
28+
public class Utils {
29+
30+
private Utils() {
31+
}
32+
33+
/**
34+
* Checks if the two 2d arrays have identical contents.
35+
*
36+
* @param message the message to be displayed
37+
* @param expected the 2d array of expected results
38+
* @param actual the 2d array of actual results
39+
*/
40+
public static void compare(String message, String[][] expected, String[][] actual) {
41+
Assert.assertEquals(message+" - outer array size", expected.length, actual.length);
42+
for(int i = 0; i < expected.length; i++) {
43+
Assert.assertArrayEquals(message+" (entry "+i+")",expected[i], actual[i]);
44+
}
45+
}
46+
47+
/**
48+
* Checks if the 2d array has the same contents as the list of records.
49+
*
50+
* @param message the message to be displayed
51+
* @param expected the 2d array of expected results
52+
* @param actual the List of {@link CSVRecord} entries, each containing an array of values
53+
*/
54+
public static void compare(String message, String[][] expected, List<CSVRecord> actual) {
55+
Assert.assertEquals(message+" - outer array size", expected.length, actual.size());
56+
for(int i = 0; i < expected.length; i++) {
57+
Assert.assertArrayEquals(message+" (entry "+i+")",expected[i], actual.get(i).values());
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)