@Override public void doAssert() { org.testng.Assert.assertEqualsNoOrder(actual, expected); } });
@Override public void doAssert() { org.testng.Assert.assertEqualsNoOrder(actual, expected, message); } });
/** * Asserts that two arrays contain the same elements in no particular order. If they do not, * an AssertionError is thrown. * @param actual the actual value * @param expected the expected value */ public static void assertEqualsNoOrder(Object[] actual, Object[] expected) { assertEqualsNoOrder(actual, expected, null); }
@Override public void doAssert() { org.testng.Assert.assertEqualsNoOrder(actual, expected, message); } });
@Override public void doAssert() { org.testng.Assert.assertEqualsNoOrder(actual, expected); } });
/** * Asserts that two arrays contain the same elements in no particular order. If they do not, an * AssertionError is thrown. * * @param actual the actual value * @param expected the expected value */ public static void assertEqualsNoOrder(Object[] actual, Object[] expected) { assertEqualsNoOrder(actual, expected, null); }
@Test public void noOrderSuccess() { String[] rto1 = { "boolean", "BigInteger", "List",}; String[] rto2 = { "List", "BigInteger", "boolean",}; Assert.assertEqualsNoOrder(rto1, rto2); }
@Test(expectedExceptions = AssertionError.class) public void noOrderFailure() { String[] rto1 = { "a", "a", "b",}; String[] rto2 = { "a", "b", "b",}; Assert.assertEqualsNoOrder(rto1, rto2); }
@Test public void nullObjectArrayAssertNoOrder() { Object[] expected= null; Object[] actual= null; Assert.assertEqualsNoOrder(actual, expected); }
@Test public void verifyTestDependsOnGroupsInheritance() throws SecurityException, NoSuchMethodException { Map<String, List<String>> dataset = new HashMap<>(); dataset.put("dependsOnGroups1", Arrays.asList("dog2", "dog1", "dog3")); dataset.put("dependsOnGroups2", Arrays.asList("dog1", "dog3")); for (Map.Entry<String, List<String>> data : dataset.entrySet()) { Method method = MTest3.class.getMethod(data.getKey()); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); List<String> expected = data.getValue(); Assert.assertEqualsNoOrder(expected.toArray(new String[expected.size()]), test1.getDependsOnGroups()); } }
protected static void verifyInstanceNames(Map<String, List<ITestResult>> actual, String[] expected) { List<String> actualNames = Lists.newArrayList(); for (Map.Entry<String, List<ITestResult>> es : actual.entrySet()) { for (ITestResult tr : es.getValue()) { Object instance = tr.getInstance(); actualNames.add(es.getKey() + "#" + (instance != null ? instance.toString() : "")); } } Assert.assertEqualsNoOrder(actualNames.toArray(), expected); }
@Test public void verifyTestGroupsInheritance() throws SecurityException, NoSuchMethodException { Map<String, List<String>> dataset = new HashMap<>(); dataset.put("groups1", Arrays.asList("method-test3", "child-class-test3", "base-class")); dataset.put("groups2", Arrays.asList("child-class-test3", "base-class")); for (Map.Entry<String, List<String>> data : dataset.entrySet()) { Method method = MTest3.class.getMethod(data.getKey()); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); List<String> expected = data.getValue(); Assert.assertEqualsNoOrder(expected.toArray(new String[expected.size()]), test1.getGroups()); } }
@Test public void verifyTestDependsOnMethodsInheritance() throws SecurityException, NoSuchMethodException { Map<String, List<String>> dataset = new HashMap<>(); dataset.put("dependsOnMethods1", Arrays.asList("dom2", "dom3", "dom1")); dataset.put("dependsOnMethods2", Arrays.asList("dom1", "dom3")); for (Map.Entry<String, List<String>> data : dataset.entrySet()) { Method method = MTest3.class.getMethod(data.getKey()); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); List<String> expected = data.getValue(); Assert.assertEqualsNoOrder(expected.toArray(new String[expected.size()]), test1.getDependsOnMethods()); } }
@Test public void verifyConfigurationGroupsInheritance() throws SecurityException, NoSuchMethodException { Method method = MTest3.class.getMethod("beforeSuite"); IConfigurationAnnotation test1 = (IConfigurationAnnotation) m_finder.findAnnotation(method, IBeforeSuite.class); Assert.assertEqualsNoOrder(new String[] { "method-test3"}, test1.getGroups()); }
public void verifyTestMethodLevel() throws SecurityException, NoSuchMethodException { // // Tests on MTest1SampleTest // Method method = MTest1.class.getMethod("f"); ITestAnnotation test1 = m_finder.findAnnotation(method, ITestAnnotation.class); Assert.assertTrue(test1.getEnabled()); Assert.assertEqualsNoOrder(test1.getGroups(), new String[] { "group1", "group3", "group4", "group2" }); Assert.assertTrue(test1.getAlwaysRun()); Assert.assertEqualsNoOrder(test1.getDependsOnGroups(), new String[] { "dg1", "dg2", "dg3", "dg4" }); Assert.assertEqualsNoOrder(test1.getDependsOnMethods(), new String[] { "dm1", "dm2", "dm3", "dm4" }); Assert.assertEquals(test1.getTimeOut(), 142); Assert.assertEquals(test1.getInvocationCount(), 143); Assert.assertEquals(test1.getSuccessPercentage(), 61); Assert.assertEquals(test1.getDataProvider(), "dp2"); Assert.assertEquals(test1.getDescription(), "Method description"); Class[] exceptions = test1.getExpectedExceptions(); Assert.assertEquals(exceptions.length, 1); Assert.assertEquals(exceptions[0], NullPointerException.class); }
@Test(invocationCount = 500) public void testInvocationCounterIsCorrectForMethodWithDataProvider() { final TestNG tng = create(FailedDPTest.class); tng.setThreadCount(1); tng.setParallel(XmlSuite.ParallelMode.NONE); tng.setPreserveOrder(true); final TestListenerAdapter tla = new TestListenerAdapter(); tng.addListener((ITestNGListener) tla); tng.run(); ITestNGMethod method = tla.getTestContexts().get(0).getAllTestMethods()[0]; List<Integer> failed = method.getFailedInvocationNumbers(); assertEqualsNoOrder(failed.toArray(), FailedDPTest.primes.toArray()); } }
public void verifyTestClassLevel() { // // Tests on MTest1SampleTest // ITestAnnotation test1 = m_finder.findAnnotation(MTest1.class, ITestAnnotation.class); Assert.assertTrue(test1.getEnabled()); Assert.assertEquals(test1.getGroups(), new String[] { "group1", "group2" }); Assert.assertTrue(test1.getAlwaysRun()); Assert.assertEqualsNoOrder(test1.getDependsOnGroups(), new String[] { "dg1", "dg2" }, "depends on groups"); Assert.assertEqualsNoOrder( test1.getDependsOnMethods(), new String[] { "dm1", "dm2" }); Assert.assertEquals(test1.getTimeOut(), 42); Assert.assertEquals(test1.getInvocationCount(), 43); Assert.assertEquals(test1.getSuccessPercentage(), 44); Assert.assertEquals(test1.getThreadPoolSize(), 3); Assert.assertEquals(test1.getDataProvider(), "dp"); Assert.assertEquals(test1.getDescription(), "Class level description"); // // Tests on MTest1SampleTest (test defaults) // ITestAnnotation test2 = m_finder.findAnnotation(MTest2.class, ITestAnnotation.class); // test default for enabled Assert.assertTrue(test2.getEnabled()); Assert.assertFalse(test2.getAlwaysRun()); Assert.assertEquals(test2.getTimeOut(), 0); Assert.assertEquals(test2.getInvocationCount(), 1); Assert.assertEquals(test2.getSuccessPercentage(), 100); Assert.assertEquals(test2.getDataProvider(), ""); }
private void runTest(String text, UrlDetectorOptions options, String... expected) { //do the detection UrlDetector parser = new UrlDetector(text, options); List<Url> found = parser.detect(); String[] foundArray = new String[found.size()]; for (int i = 0; i < foundArray.length; i++) { foundArray[i] = found.get(i).getOriginalUrl(); } Assert.assertEqualsNoOrder(foundArray, expected); } }
@Test public void testCopyDirectoryTree() throws IOException { final Path copyToDir = Files.createTempDirectory("copyToDir"); copyToDir.toFile().deleteOnExit(); IOUtil.copyDirectoryTree(TEST_VARIANT_DIR.toFile(), copyToDir.toFile()); final List<Path> collect = Files.walk(TEST_VARIANT_DIR).filter(f -> !f.equals(TEST_VARIANT_DIR)).map(p -> p.getFileName()).collect(Collectors.toList()); final List<Path> collectCopy = Files.walk(copyToDir).filter(f -> !f.equals(copyToDir)).map(p -> p.getFileName()).collect(Collectors.toList()); Assert.assertEqualsNoOrder(collect.toArray(), collectCopy.toArray()); }
private void assertGetTypeVariableConstraints(List<String> inputParameterSignatures, String outputParameterSignature, List<TypeVariableConstraint> expectedTypeVariableConstraints) { ExampleStdUDF exampleStdUDF = new ExampleStdUDF(inputParameterSignatures, outputParameterSignature); Assert.assertEqualsNoOrder(StdUdfWrapper.getTypeVariableConstraintsForStdUdf(exampleStdUDF).toArray(), expectedTypeVariableConstraints.toArray()); }