| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2015 ForgeRock AS. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | */ |
| | | package org.opends.server.util; |
| | | |
| | | import static org.opends.server.util.CollectionUtils.*; |
| | | import static org.testng.Assert.*; |
| | | |
| | | import java.io.BufferedReader; |
| | |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.channels.FileLock; |
| | | import java.text.ParseException; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.Collections; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * Create test strings for the |
| | | * {@link StaticUtils#isRelativePath(String)}. |
| | | * |
| | | * @return Returns an array of test data. |
| | | */ |
| | | @DataProvider(name = "isRelativePathTestData") |
| | | public Object[][] createIsRelativePathTestData() { |
| | | String root = File.listRoots()[0].getPath(); |
| | | return new Object[][] { { "", true }, { root, false }, |
| | | { root + "foo", false }, { "foo", true }, |
| | | { "foo" + File.separator + "bar", true }, |
| | | { root + "foo" + File.separator + "bar", false }, |
| | | { ".", true }, { "..", true }, |
| | | { root + "foo" + File.separator + ".", false }, |
| | | { root + "foo" + File.separator + "..", false } }; |
| | | } |
| | | |
| | | /** |
| | | * Tests the {@link StaticUtils#isRelativePath(String)} method. |
| | | * |
| | | * @param path |
| | | * The test string. |
| | | * @param result |
| | | * Expected result. |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test(dataProvider = "isRelativePathTestData") |
| | | public void testIsRelativePath(String path, boolean result) |
| | | throws Exception { |
| | | Assert.assertEquals(StaticUtils.isRelativePath(path), result); |
| | | } |
| | | |
| | | /** |
| | | * Create test lists for the {@link StaticUtils#listToArray(List)}. |
| | | * |
| | | * @return Returns an array of test data. |
| | | */ |
| | | @DataProvider(name = "listToArrayTestData") |
| | | public Object[][] createListToArrayTestData() { |
| | | return new Object[][] { { null }, { new String[] {} }, |
| | | { new String[] { "aaa" } }, |
| | | { new String[] { "aaa", "bbb", "ccc" } } }; |
| | | } |
| | | |
| | | /** |
| | | * Tests the {@link StaticUtils#listToArray(List)} method. |
| | | * |
| | | * @param strings |
| | | * The test string list. |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test(dataProvider = "listToArrayTestData") |
| | | public void testListToArray(String[] strings) throws Exception { |
| | | if (strings != null) { |
| | | List<String> list = new ArrayList<>(strings.length); |
| | | Collections.addAll(list, strings); |
| | | Assert.assertEquals(StaticUtils.listToArray(list), strings); |
| | | } else { |
| | | Assert.assertNull(StaticUtils.listToArray(null)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Tests the {@link StaticUtils#moveFile(java.io.File, java.io.File)} |
| | | * method. |
| | | * |
| | |
| | | Assert.assertEquals(builder.toString(), expected); |
| | | } |
| | | |
| | | /** |
| | | * Create test lists for the |
| | | * {@link StaticUtils#listsAreEqual(List, List)} method. |
| | | * |
| | | * @return Returns an array of test data. |
| | | */ |
| | | @DataProvider(name = "listsAreEqualTestData") |
| | | public Object[][] createListsAreEqualTestData() { |
| | | return new Object[][] { |
| | | // Check null behaviour. |
| | | { null, null, true }, |
| | | { null, Collections.emptyList(), false }, |
| | | { Collections.emptyList(), null, false }, |
| | | |
| | | // Check empty-list behaviour. |
| | | { Collections.emptyList(), Collections.emptyList(), true }, |
| | | { Collections.singletonList(0), Collections.emptyList(), false }, |
| | | { Collections.emptyList(), Collections.singletonList(0), false }, |
| | | |
| | | // Check single-element behaviour. |
| | | { Collections.singletonList(0), Collections.singletonList(0), true }, |
| | | { Collections.singletonList(0), Collections.singletonList(1), false }, |
| | | |
| | | // Check multi-element random access behaviour. |
| | | { Arrays.asList(0, 1), Arrays.asList(0, 1), true }, |
| | | { Arrays.asList(0, 1), Arrays.asList(1, 0), false }, |
| | | |
| | | // ...With duplicates. |
| | | { Arrays.asList(0, 1), Arrays.asList(0, 1, 1), false }, |
| | | |
| | | // Check multi-element sequential behaviour. |
| | | { newLinkedList(0, 1), newLinkedList(0, 1), true }, |
| | | { newLinkedList(0, 1), newLinkedList(1, 0), false }, |
| | | |
| | | // ...With duplicates. |
| | | { newLinkedList(0, 1), newLinkedList(0, 1, 1), false } }; |
| | | } |
| | | |
| | | /** |
| | | * Tests the {@link StaticUtils#listsAreEqual(List, List)} method. |
| | | * |
| | | * @param list1 |
| | | * The first list. |
| | | * @param list2 |
| | | * The second list. |
| | | * @param result |
| | | * The expected equality result. |
| | | * @throws Exception |
| | | * If the test failed unexpectedly. |
| | | */ |
| | | @Test(dataProvider = "listsAreEqualTestData") |
| | | public void testListsAreEqual(List<?> list1, List<?> list2, boolean result) |
| | | throws Exception { |
| | | Assert.assertEquals(StaticUtils.listsAreEqual(list1, list2), result); |
| | | } |
| | | |
| | | @Test |
| | | public void testStackTraceHasCause() throws Exception |
| | | { |