From 05f881c2af8fae237a59f3d72f553b68eb327f9d Mon Sep 17 00:00:00 2001
From: Piotr Gawron <piotr.gawron@uni.lu>
Date: Fri, 26 Jul 2019 14:32:38 +0200
Subject: [PATCH] unnecessary try catch statements removed

---
 .../dao/graphics/PolylineDataTest.java        |  64 ++-
 .../persist/dao/user/UserDaoTest.java         | 401 ++++++++----------
 2 files changed, 197 insertions(+), 268 deletions(-)

diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/graphics/PolylineDataTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/graphics/PolylineDataTest.java
index c483920daa..84914165c6 100644
--- a/persist/src/test/java/lcsb/mapviewer/persist/dao/graphics/PolylineDataTest.java
+++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/graphics/PolylineDataTest.java
@@ -2,7 +2,7 @@ package lcsb.mapviewer.persist.dao.graphics;
 
 import static org.junit.Assert.*;
 
-import java.awt.*;
+import java.awt.Color;
 import java.awt.geom.Point2D;
 
 import org.junit.*;
@@ -26,40 +26,34 @@ public class PolylineDataTest extends PersistTestFunctions {
 
   @Test
   public void test() {
-    try {
-      PolylineData pd = new PolylineData();
-      pd.getBeginAtd().setArrowType(ArrowType.BLANK_CROSSBAR);
-      pd.getBeginAtd().setArrowLineType(LineType.DASHED);
-      pd.getBeginAtd().setLen(102);
-      pd.setColor(Color.CYAN);
-      pd.setType(LineType.SOLID_BOLD);
-      pd.setWidth(2);
-      pd.getPoints().add(new Point2D.Double(1, 1));
-      pd.getPoints().add(new Point2D.Double(2, 3));
-      pd.getPoints().add(new Point2D.Double(10, 11));
-      polylineDao.add(pd);
-      assertNotNull(pd.getId());
-      PolylineData pd2 = polylineDao.getById(pd.getId());
-      assertNotNull(pd2);
-
-      assertEquals(ArrowType.BLANK_CROSSBAR, pd2.getBeginAtd().getArrowType());
-      assertEquals(LineType.DASHED, pd2.getBeginAtd().getArrowLineType());
-      assertEquals(102, pd2.getBeginAtd().getLen(), EPSILON);
-      assertEquals(Color.CYAN, pd2.getColor());
-      assertEquals(LineType.SOLID_BOLD, pd2.getType());
-      assertEquals(2, pd2.getWidth(), EPSILON);
-      assertEquals(0, pd2.getPoints().get(0).distance(new Point2D.Double(1, 1)), EPSILON);
-      assertEquals(0, pd2.getPoints().get(1).distance(new Point2D.Double(2, 3)), EPSILON);
-      assertEquals(0, pd2.getPoints().get(2).distance(new Point2D.Double(10, 11)), EPSILON);
-
-      polylineDao.delete(pd);
-      pd2 = polylineDao.getById(pd.getId());
-      assertNull(pd2);
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    PolylineData pd = new PolylineData();
+    pd.getBeginAtd().setArrowType(ArrowType.BLANK_CROSSBAR);
+    pd.getBeginAtd().setArrowLineType(LineType.DASHED);
+    pd.getBeginAtd().setLen(102);
+    pd.setColor(Color.CYAN);
+    pd.setType(LineType.SOLID_BOLD);
+    pd.setWidth(2);
+    pd.getPoints().add(new Point2D.Double(1, 1));
+    pd.getPoints().add(new Point2D.Double(2, 3));
+    pd.getPoints().add(new Point2D.Double(10, 11));
+    polylineDao.add(pd);
+    assertNotNull(pd.getId());
+    PolylineData pd2 = polylineDao.getById(pd.getId());
+    assertNotNull(pd2);
+
+    assertEquals(ArrowType.BLANK_CROSSBAR, pd2.getBeginAtd().getArrowType());
+    assertEquals(LineType.DASHED, pd2.getBeginAtd().getArrowLineType());
+    assertEquals(102, pd2.getBeginAtd().getLen(), EPSILON);
+    assertEquals(Color.CYAN, pd2.getColor());
+    assertEquals(LineType.SOLID_BOLD, pd2.getType());
+    assertEquals(2, pd2.getWidth(), EPSILON);
+    assertEquals(0, pd2.getPoints().get(0).distance(new Point2D.Double(1, 1)), EPSILON);
+    assertEquals(0, pd2.getPoints().get(1).distance(new Point2D.Double(2, 3)), EPSILON);
+    assertEquals(0, pd2.getPoints().get(2).distance(new Point2D.Double(10, 11)), EPSILON);
+
+    polylineDao.delete(pd);
+    pd2 = polylineDao.getById(pd.getId());
+    assertNull(pd2);
   }
 
 }
diff --git a/persist/src/test/java/lcsb/mapviewer/persist/dao/user/UserDaoTest.java b/persist/src/test/java/lcsb/mapviewer/persist/dao/user/UserDaoTest.java
index 363cb67214..b7192d7344 100644
--- a/persist/src/test/java/lcsb/mapviewer/persist/dao/user/UserDaoTest.java
+++ b/persist/src/test/java/lcsb/mapviewer/persist/dao/user/UserDaoTest.java
@@ -38,298 +38,233 @@ public class UserDaoTest extends PersistTestFunctions {
 
   @Test
   public void testAddUpdateDelete() {
-    try {
-      User user = userDao.getUserByLogin(testLogin);
-      assertNull(user);
+    User user = userDao.getUserByLogin(testLogin);
+    assertNull(user);
 
-      long counter = userDao.getCount();
+    long counter = userDao.getCount();
 
-      user = new User();
-      user.setCryptedPassword("");
-      user.setLogin(testLogin);
-      user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
-      userDao.add(user);
+    user = new User();
+    user.setCryptedPassword("");
+    user.setLogin(testLogin);
+    user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
+    userDao.add(user);
 
-      long counter2 = userDao.getCount();
-      assertEquals(counter + 1, counter2);
+    long counter2 = userDao.getCount();
+    assertEquals(counter + 1, counter2);
 
-      user.setLogin(testLogin2);
-      userDao.update(user);
+    user.setLogin(testLogin2);
+    userDao.update(user);
 
-      User user2 = userDao.getUserByLogin(testLogin2);
-      assertNotNull(user2);
+    User user2 = userDao.getUserByLogin(testLogin2);
+    assertNotNull(user2);
 
-      userDao.delete(user);
+    userDao.delete(user);
 
-      user2 = userDao.getUserByLogin(testLogin2);
-      assertNull(user2);
-      counter2 = userDao.getCount();
-      assertEquals(counter, counter2);
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    user2 = userDao.getUserByLogin(testLogin2);
+    assertNull(user2);
+    counter2 = userDao.getCount();
+    assertEquals(counter, counter2);
   }
 
   @Test(expected = PropertyValueException.class)
   public void testTryUserWithNullPassword() {
-    try {
-      User user = new User();
-      user.setLogin(testLogin);
-      userDao.add(user);
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setLogin(testLogin);
+    userDao.add(user);
   }
 
   @Test(expected = PropertyValueException.class)
   public void testTryUserWithNullLogin() {
-    try {
-      User user = new User();
-      user.setCryptedPassword("ZX");
-      userDao.add(user);
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setCryptedPassword("ZX");
+    userDao.add(user);
   }
 
   @Test(expected = ConstraintViolationException.class)
   public void testTryUserWithExistingLogin() {
-    try {
-      User user = new User();
-      user.setLogin(testLogin);
-      user.setCryptedPassword("");
-      userDao.add(user);
-
-      User user2 = new User();
-      user2.setLogin(testLogin);
-      user2.setCryptedPassword("");
-      userDao.add(user2);
-
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setLogin(testLogin);
+    user.setCryptedPassword("");
+    userDao.add(user);
+
+    User user2 = new User();
+    user2.setLogin(testLogin);
+    user2.setCryptedPassword("");
+    userDao.add(user2);
   }
 
   @Test
   public void testAddDeleteAdd() {
-    try {
-      User user = userDao.getUserByLogin(testLogin);
-      assertNull(user);
-
-      long counter = userDao.getCount();
+    User user = userDao.getUserByLogin(testLogin);
+    assertNull(user);
 
-      user = new User();
-      user.setLogin(testLogin);
-      user.setCryptedPassword("");
-      userDao.add(user);
+    long counter = userDao.getCount();
 
-      long counter2 = userDao.getCount();
-      assertEquals(counter + 1, counter2);
+    user = new User();
+    user.setLogin(testLogin);
+    user.setCryptedPassword("");
+    userDao.add(user);
 
-      userDao.delete(user);
+    long counter2 = userDao.getCount();
+    assertEquals(counter + 1, counter2);
 
-      User user2 = userDao.getUserByLogin(testLogin);
-      assertNull(user2);
+    userDao.delete(user);
 
-      user2 = new User();
-      user2.setCryptedPassword("");
-      user2.setLogin(testLogin);
-      userDao.add(user2);
+    User user2 = userDao.getUserByLogin(testLogin);
+    assertNull(user2);
 
-      assertNotNull(userDao.getUserByLogin(testLogin));
+    user2 = new User();
+    user2.setCryptedPassword("");
+    user2.setLogin(testLogin);
+    userDao.add(user2);
 
-      userDao.delete(user2);
+    assertNotNull(userDao.getUserByLogin(testLogin));
 
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    userDao.delete(user2);
   }
 
   @Test
   public void testGetUserByLogin() throws Exception {
-    try {
-      User user = new User();
-      user.setCryptedPassword(testPasswd);
-      user.setLogin(testLogin);
-      userDao.add(user);
-      User user2 = userDao.getUserByLogin(testLogin);
-      assertNotNull(user2);
-      assertEquals(user2.getId(), user.getId());
-      assertEquals(user2.getLogin(), user.getLogin());
-      assertEquals(user2.getCryptedPassword(), user.getCryptedPassword());
-      user2 = userDao.getUserByLogin(testLogin2);
-      assertNull(user2);
-      userDao.delete(user);
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setCryptedPassword(testPasswd);
+    user.setLogin(testLogin);
+    userDao.add(user);
+    User user2 = userDao.getUserByLogin(testLogin);
+    assertNotNull(user2);
+    assertEquals(user2.getId(), user.getId());
+    assertEquals(user2.getLogin(), user.getLogin());
+    assertEquals(user2.getCryptedPassword(), user.getCryptedPassword());
+    user2 = userDao.getUserByLogin(testLogin2);
+    assertNull(user2);
+    userDao.delete(user);
   }
 
   @Test
   public void testGetUserByEmail() throws Exception {
-    try {
-      User user = new User();
-      user.setCryptedPassword(testPasswd);
-      user.setLogin(testLogin);
-      user.setEmail(testEmail);
-      user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
-      userDao.add(user);
-      User user2 = userDao.getUserByEmail(testEmail);
-      assertNotNull(user2);
-      assertEquals(user2.getId(), user.getId());
-      assertEquals(user2.getLogin(), user.getLogin());
-      assertEquals(user2.getCryptedPassword(), user.getCryptedPassword());
-      user2 = userDao.getUserByEmail(testEmail + "sadas");
-      assertNull(user2);
-      userDao.delete(user);
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setCryptedPassword(testPasswd);
+    user.setLogin(testLogin);
+    user.setEmail(testEmail);
+    user.addPrivilege(new Privilege(PrivilegeType.CAN_CREATE_OVERLAYS));
+    userDao.add(user);
+    User user2 = userDao.getUserByEmail(testEmail);
+    assertNotNull(user2);
+    assertEquals(user2.getId(), user.getId());
+    assertEquals(user2.getLogin(), user.getLogin());
+    assertEquals(user2.getCryptedPassword(), user.getCryptedPassword());
+    user2 = userDao.getUserByEmail(testEmail + "sadas");
+    assertNull(user2);
+    userDao.delete(user);
   }
 
   @Test
   public void testGetAll() throws Exception {
-    try {
-      assertTrue(userDao.getAll().size() > 0);
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    assertTrue(userDao.getAll().size() > 0);
   }
 
   @Test
   public void testUserWithAnnotatorSchema() throws Exception {
-    try {
-      User user = new User();
-      user.setLogin(testLogin);
-      user.setCryptedPassword("");
-      UserAnnotationSchema uas = new UserAnnotationSchema();
-      uas.setValidateMiriamTypes(true);
-      UserClassAnnotators ca = new UserClassAnnotators();
-      ca.setClassName(Species.class);
-      AnnotatorData annotatorData = new AnnotatorData(String.class);
-      ca.addAnnotator(annotatorData);
-      uas.addClassAnnotator(ca);
-      uas.addClassAnnotator(new UserClassAnnotators(String.class, new ArrayList<>()));
-      UserClassValidAnnotations cva = new UserClassValidAnnotations();
-      cva.setClassName(Reaction.class);
-      cva.addValidMiriamType(MiriamType.HGNC);
-      cva.addValidMiriamType(MiriamType.HGNC_SYMBOL);
-      uas.addClassValidAnnotations(cva);
-      uas.addClassValidAnnotations(new UserClassValidAnnotations(String.class, new ArrayList<>()));
-      uas.addClassValidAnnotations(new UserClassValidAnnotations(Integer.class, new ArrayList<>()));
-      user.setAnnotationSchema(uas);
-      userDao.add(user);
-      userDao.evict(user);
-      User user2 = userDao.getById(user.getId());
-      assertNotNull(user2);
-      UserAnnotationSchema uas2 = user2.getAnnotationSchema();
-      assertNotNull(uas2);
-      assertEquals(2, uas2.getClassAnnotators().size());
-      assertEquals(3, uas2.getClassValidAnnotators().size());
-      assertEquals(Species.class.getCanonicalName(), uas.getClassAnnotators().get(0).getClassName());
-      assertEquals(annotatorData, uas.getClassAnnotators().get(0).getAnnotators().get(0));
-      assertEquals(Reaction.class.getCanonicalName(), uas.getClassValidAnnotators().get(0).getClassName());
-      assertEquals(MiriamType.HGNC, uas.getClassValidAnnotators().get(0).getValidMiriamTypes().get(0));
-      assertEquals(MiriamType.HGNC_SYMBOL, uas.getClassValidAnnotators().get(0).getValidMiriamTypes().get(1));
-
-      userDao.delete(user2);
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setLogin(testLogin);
+    user.setCryptedPassword("");
+    UserAnnotationSchema uas = new UserAnnotationSchema();
+    uas.setValidateMiriamTypes(true);
+    UserClassAnnotators ca = new UserClassAnnotators();
+    ca.setClassName(Species.class);
+    AnnotatorData annotatorData = new AnnotatorData(String.class);
+    ca.addAnnotator(annotatorData);
+    uas.addClassAnnotator(ca);
+    uas.addClassAnnotator(new UserClassAnnotators(String.class, new ArrayList<>()));
+    UserClassValidAnnotations cva = new UserClassValidAnnotations();
+    cva.setClassName(Reaction.class);
+    cva.addValidMiriamType(MiriamType.HGNC);
+    cva.addValidMiriamType(MiriamType.HGNC_SYMBOL);
+    uas.addClassValidAnnotations(cva);
+    uas.addClassValidAnnotations(new UserClassValidAnnotations(String.class, new ArrayList<>()));
+    uas.addClassValidAnnotations(new UserClassValidAnnotations(Integer.class, new ArrayList<>()));
+    user.setAnnotationSchema(uas);
+    userDao.add(user);
+    userDao.evict(user);
+    User user2 = userDao.getById(user.getId());
+    assertNotNull(user2);
+    UserAnnotationSchema uas2 = user2.getAnnotationSchema();
+    assertNotNull(uas2);
+    assertEquals(2, uas2.getClassAnnotators().size());
+    assertEquals(3, uas2.getClassValidAnnotators().size());
+    assertEquals(Species.class.getCanonicalName(), uas.getClassAnnotators().get(0).getClassName());
+    assertEquals(annotatorData, uas.getClassAnnotators().get(0).getAnnotators().get(0));
+    assertEquals(Reaction.class.getCanonicalName(), uas.getClassValidAnnotators().get(0).getClassName());
+    assertEquals(MiriamType.HGNC, uas.getClassValidAnnotators().get(0).getValidMiriamTypes().get(0));
+    assertEquals(MiriamType.HGNC_SYMBOL, uas.getClassValidAnnotators().get(0).getValidMiriamTypes().get(1));
+
+    userDao.delete(user2);
   }
 
   @Test
   public void testUserWithAnnotatorSchemaGuiPreferences() throws Exception {
-    try {
-      User user = new User();
-      user.setLogin(testLogin);
-      user.setCryptedPassword("");
-      UserAnnotationSchema uas = new UserAnnotationSchema();
-      user.setAnnotationSchema(uas);
-      UserGuiPreference option = new UserGuiPreference();
-      option.setKey("key");
-      option.setValue("val");
-      uas.addGuiPreference(option);
-      userDao.add(user);
-      userDao.evict(user);
-      User user2 = userDao.getById(user.getId());
-      assertNotNull(user2);
-      UserAnnotationSchema uas2 = user2.getAnnotationSchema();
-      assertNotNull(uas2);
-      assertEquals(1, uas2.getGuiPreferences().size());
-
-      userDao.delete(user2);
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setLogin(testLogin);
+    user.setCryptedPassword("");
+    UserAnnotationSchema uas = new UserAnnotationSchema();
+    user.setAnnotationSchema(uas);
+    UserGuiPreference option = new UserGuiPreference();
+    option.setKey("key");
+    option.setValue("val");
+    uas.addGuiPreference(option);
+    userDao.add(user);
+    userDao.evict(user);
+    User user2 = userDao.getById(user.getId());
+    assertNotNull(user2);
+    UserAnnotationSchema uas2 = user2.getAnnotationSchema();
+    assertNotNull(uas2);
+    assertEquals(1, uas2.getGuiPreferences().size());
+
+    userDao.delete(user2);
   }
 
   @Test
   public void testUserWithAnnotatorSchemaRequiredAnnotations() throws Exception {
-    try {
-      User user = new User();
-      user.setLogin(testLogin);
-      user.setCryptedPassword("");
-      UserAnnotationSchema uas = new UserAnnotationSchema();
-      user.setAnnotationSchema(uas);
-      uas.addClassRequiredAnnotations(
-          new UserClassRequiredAnnotations(String.class, new MiriamType[] { MiriamType.WIKIPEDIA }));
-      userDao.add(user);
-      userDao.evict(user);
-      User user2 = userDao.getById(user.getId());
-      assertNotNull(user2);
-      UserAnnotationSchema uas2 = user2.getAnnotationSchema();
-      assertNotNull(uas2);
-      assertEquals(1, uas2.getClassRequiredAnnotators().size());
-
-      userDao.delete(user2);
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setLogin(testLogin);
+    user.setCryptedPassword("");
+    UserAnnotationSchema uas = new UserAnnotationSchema();
+    user.setAnnotationSchema(uas);
+    uas.addClassRequiredAnnotations(
+        new UserClassRequiredAnnotations(String.class, new MiriamType[] { MiriamType.WIKIPEDIA }));
+    userDao.add(user);
+    userDao.evict(user);
+    User user2 = userDao.getById(user.getId());
+    assertNotNull(user2);
+    UserAnnotationSchema uas2 = user2.getAnnotationSchema();
+    assertNotNull(uas2);
+    assertEquals(1, uas2.getClassRequiredAnnotators().size());
+
+    userDao.delete(user2);
   }
 
   @Test
   public void testUserWithAnnotatorParams() throws Exception {
-    try {
-      User user = new User();
-      user.setLogin(testLogin);
-      user.setCryptedPassword("");
-      UserAnnotationSchema uas = new UserAnnotationSchema();
-      user.setAnnotationSchema(uas);
-      UserClassAnnotators classAnnotators = new UserClassAnnotators(Integer.class);
-      AnnotatorData annotatorData = new AnnotatorData(String.class);
-      classAnnotators.addAnnotator(annotatorData);
-      uas.addClassAnnotator(classAnnotators);
-      AnnotatorConfigParameter param = new AnnotatorConfigParameter(AnnotatorParamDefinition.KEGG_ORGANISM_IDENTIFIER,
-          "val");
-      annotatorData.addAnnotatorParameter(param);
-      userDao.add(user);
-      userDao.evict(user);
-      User user2 = userDao.getById(user.getId());
-      assertNotNull(user2);
-      UserAnnotationSchema uas2 = user2.getAnnotationSchema();
-      assertNotNull(uas2);
-      assertEquals(1, uas2.getClassAnnotators().get(0).getAnnotators().get(0).getAnnotatorParams().size());
-
-      userDao.delete(user2);
-    } catch (Exception e) {
-      e.printStackTrace();
-      throw e;
-    }
+    User user = new User();
+    user.setLogin(testLogin);
+    user.setCryptedPassword("");
+    UserAnnotationSchema uas = new UserAnnotationSchema();
+    user.setAnnotationSchema(uas);
+    UserClassAnnotators classAnnotators = new UserClassAnnotators(Integer.class);
+    AnnotatorData annotatorData = new AnnotatorData(String.class);
+    classAnnotators.addAnnotator(annotatorData);
+    uas.addClassAnnotator(classAnnotators);
+    AnnotatorConfigParameter param = new AnnotatorConfigParameter(AnnotatorParamDefinition.KEGG_ORGANISM_IDENTIFIER,
+        "val");
+    annotatorData.addAnnotatorParameter(param);
+    userDao.add(user);
+    userDao.evict(user);
+    User user2 = userDao.getById(user.getId());
+    assertNotNull(user2);
+    UserAnnotationSchema uas2 = user2.getAnnotationSchema();
+    assertNotNull(uas2);
+    assertEquals(1, uas2.getClassAnnotators().get(0).getAnnotators().get(0).getAnnotatorParams().size());
+
+    userDao.delete(user2);
   }
 
 }
-- 
GitLab