From 48fb447ce42a6df6ff0b5ca268e3af636963d39f Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 6 Jul 2018 11:56:32 +0200 Subject: [PATCH] test modified to use mockito --- .../species/field/AntisenseRnaRegionTest.java | 303 +++++++++--------- 1 file changed, 150 insertions(+), 153 deletions(-) diff --git a/model/src/test/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegionTest.java b/model/src/test/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegionTest.java index 2821caabaf..a84a65a853 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegionTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/species/field/AntisenseRnaRegionTest.java @@ -8,166 +8,163 @@ import org.apache.commons.lang3.SerializationUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.NotImplementedException; +import lcsb.mapviewer.model.map.modifier.Catalysis; import lcsb.mapviewer.model.map.species.AntisenseRna; +import lcsb.mapviewer.model.map.species.Drug; public class AntisenseRnaRegionTest { - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new AntisenseRnaRegion()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor1() { - try { - AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); - AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(antisenseRna); - assertNotNull(antisenseRna2); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testUpdate() { - try { - AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); - antisenseRna.setState(ModificationState.EMPTY); - antisenseRna.setName("as"); - antisenseRna.setPos(3.0); - AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(); - antisenseRna2.update(antisenseRna); - assertEquals(antisenseRna.getState(), antisenseRna2.getState()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidUpdate() { - try { - AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); - AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(); - antisenseRna.setIdAntisenseRnaRegion("@1"); - antisenseRna2.setIdAntisenseRnaRegion("@"); - antisenseRna2.update(antisenseRna); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - AntisenseRnaRegion region = new AntisenseRnaRegion(new AntisenseRnaRegion()); - int id = 91; - AntisenseRna species = new AntisenseRna("id"); - double pos = 4.6; - double size = 5.3; - AntisenseRnaRegionType type = AntisenseRnaRegionType.CODING_REGION; - String name = "nam"; - String idAntisenseRnaRegion = "iddd"; - - region.setId(id); - region.setSpecies(species); - region.setPos(pos); - region.setSize(size); - region.setType(type); - region.setName(name); - region.setIdAntisenseRnaRegion(idAntisenseRnaRegion); - region.setState(ModificationState.ACETYLATED); - - assertEquals(id, region.getId()); - assertEquals(species, region.getSpecies()); - assertEquals(pos, region.getPos(), Configuration.EPSILON); - assertEquals(size, region.getSize(), Configuration.EPSILON); - assertEquals(type, region.getType()); - assertEquals(name, region.getName()); - assertEquals(idAntisenseRnaRegion, region.getIdAntisenseRnaRegion()); - - assertEquals(ModificationState.ACETYLATED, region.getState()); - - try { - region.setSize("text"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - - try { - region.setPos("text"); - fail("Exception expected"); - } catch (InvalidArgumentException e) { - } - - region.setSize("1.0"); - region.setPos("1.0"); - assertEquals(1.0, region.getPos(), Configuration.EPSILON); - assertEquals(1.0, region.getSize(), Configuration.EPSILON); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testToString() { - try { - assertNotNull(new AntisenseRnaRegion().toString()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - AntisenseRnaRegion degraded = new AntisenseRnaRegion().copy(); - assertNotNull(degraded); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - new AntisenseRnaRegion() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new AntisenseRnaRegion()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor1() { + try { + AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); + AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(antisenseRna); + assertNotNull(antisenseRna2); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testUpdate() { + try { + AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); + antisenseRna.setState(ModificationState.EMPTY); + antisenseRna.setName("as"); + antisenseRna.setPos(3.0); + AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(); + antisenseRna2.update(antisenseRna); + assertEquals(antisenseRna.getState(), antisenseRna2.getState()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidUpdate() { + try { + AntisenseRnaRegion antisenseRna = new AntisenseRnaRegion(); + AntisenseRnaRegion antisenseRna2 = new AntisenseRnaRegion(); + antisenseRna.setIdAntisenseRnaRegion("@1"); + antisenseRna2.setIdAntisenseRnaRegion("@"); + antisenseRna2.update(antisenseRna); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + AntisenseRnaRegion region = new AntisenseRnaRegion(new AntisenseRnaRegion()); + int id = 91; + AntisenseRna species = new AntisenseRna("id"); + double pos = 4.6; + double size = 5.3; + AntisenseRnaRegionType type = AntisenseRnaRegionType.CODING_REGION; + String name = "nam"; + String idAntisenseRnaRegion = "iddd"; + + region.setId(id); + region.setSpecies(species); + region.setPos(pos); + region.setSize(size); + region.setType(type); + region.setName(name); + region.setIdAntisenseRnaRegion(idAntisenseRnaRegion); + region.setState(ModificationState.ACETYLATED); + + assertEquals(id, region.getId()); + assertEquals(species, region.getSpecies()); + assertEquals(pos, region.getPos(), Configuration.EPSILON); + assertEquals(size, region.getSize(), Configuration.EPSILON); + assertEquals(type, region.getType()); + assertEquals(name, region.getName()); + assertEquals(idAntisenseRnaRegion, region.getIdAntisenseRnaRegion()); + + assertEquals(ModificationState.ACETYLATED, region.getState()); + + try { + region.setSize("text"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + + try { + region.setPos("text"); + fail("Exception expected"); + } catch (InvalidArgumentException e) { + } + + region.setSize("1.0"); + region.setPos("1.0"); + assertEquals(1.0, region.getPos(), Configuration.EPSILON); + assertEquals(1.0, region.getSize(), Configuration.EPSILON); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testToString() { + try { + assertNotNull(new AntisenseRnaRegion().toString()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + AntisenseRnaRegion degraded = new AntisenseRnaRegion().copy(); + assertNotNull(degraded); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + Mockito.mock(AntisenseRnaRegion.class, Mockito.CALLS_REAL_METHODS).copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } } -- GitLab