Allon Mureinik has uploaded a new change for review.

Change subject: core: DirectorySearcherTest proper failures
......................................................................

core: DirectorySearcherTest proper failures

Used the proper JUnit 4 syntax for failures - @Test with the expected
parameter, instead of the ugly hack of catching an exception and
returning before the test reaches a fail() statement.

Change-Id: Icdc729f0aa78674f45ce11aab844cbf9751a6ac6
Signed-off-by: Allon Mureinik <amure...@redhat.com>
---
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcherTest.java
1 file changed, 9 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/19/14419/1

diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcherTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcherTest.java
index f8df94e..c216a2f 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcherTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/adbroker/DirectorySearcherTest.java
@@ -20,7 +20,6 @@
 import javax.naming.NamingException;
 import javax.naming.directory.DirContext;
 
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.ClassRule;
 import org.junit.Test;
@@ -64,12 +63,8 @@
         DirectorySearcher dirSearcher = mockDirectorySearcher(urls);
         GetRootDSETask task1 = mockRootDSETask(dirSearcher, "mydomain", 
urls.get(0));
         GetRootDSETask task2 = mockRootDSETask(dirSearcher, "mydomain", 
urls.get(1));
-        try {
-            assertTrue(task1.call());
-            assertTrue(task2.call());
-        } catch (Exception e) {
-            Assert.fail("one of the servers was failed to return rootDSE 
record due to " + e.getMessage());
-        }
+        assertTrue(task1.call());
+        assertTrue(task2.call());
     }
 
     protected GetRootDSETask mockRootDSETask(DirectorySearcher dirSearcher, 
String domain, URI url) {
@@ -79,46 +74,29 @@
         return task;
     }
 
-    @Test
+    @Test(expected = TimeoutException.class)
     public void testGetRootDSEFirstSeverUnreachable() throws Exception {
         List<URI> urls = new ArrayList<URI>();
         urls.add(new URI(BAD_URL));
         urls.add(new URI("ldap://ldap1.example.com:389";));
         DirectorySearcher dirSearcher = mockDirectorySearcher(urls);
-        try {
-            execute(new GetRootDSETask(dirSearcher, "mydomain", urls.get(0)));
-        } catch (Exception e) {
-            // server should timeout!
-            return;
-        }
-        Assert.fail("Get rootDSE task passed with no timeout. Investigate why 
the task completed instead of throwing TimeoutException");
+        execute(new GetRootDSETask(dirSearcher, "mydomain", urls.get(0)));
     }
 
-    @Test
+    @Test(expected = TimeoutException.class)
     public void testGetRootDSENoServers() throws Exception {
         List<URI> urls = new ArrayList<URI>();
         DirectorySearcher dirSearcher = mockDirectorySearcher(urls);
-        try {
-            GetRootDSETask getRootDSETask = new GetRootDSETask(dirSearcher, 
"mydomain", null);
-            execute(getRootDSETask);
-        } catch (Exception e) {
-            // should fail
-            return;
-        }
-        Assert.fail("Task didn't exited with error");
+        GetRootDSETask getRootDSETask = new GetRootDSETask(dirSearcher, 
"mydomain", null);
+        execute(getRootDSETask);
     }
 
-    @Test
+    @Test(expected = TimeoutException.class)
     public void testGetRootDSENoReachableLdapServers() throws Exception {
         List<URI> urls = new ArrayList<URI>();
         urls.add(new URI(BAD_URL));
         DirectorySearcher dirSearcher = mockDirectorySearcher(urls);
-        try {
-            execute(new GetRootDSETask(dirSearcher, "mydomain", urls.get(0)));
-        } catch (TimeoutException ok) {
-            return;
-        }
-        Assert.fail("Task ended with error which is not timout or no error at 
all");
+        execute(new GetRootDSETask(dirSearcher, "mydomain", urls.get(0)));
     }
 
     private DirectorySearcher mockDirectorySearcher(final List<URI> urls) {


--
To view, visit http://gerrit.ovirt.org/14419
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icdc729f0aa78674f45ce11aab844cbf9751a6ac6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Allon Mureinik <amure...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to