From 8279643e46ad31ff9a8e873081442983ae59a46f Mon Sep 17 00:00:00 2001 From: ribeaudc <ribeaudc> Date: Mon, 5 Nov 2007 12:25:06 +0000 Subject: [PATCH] fix: - CruiseControl BDS build SVN: 2378 --- .../ch/systemsx/cisd/bds/hcs/ChannelList.java | 7 ++- .../cisd/bds/hcs/ChannelListTest.java | 58 ++++++++++++++++++- .../cisd/bds/hcs/PlateGeometryTest.java | 6 +- .../cisd/bds/hcs/WellGeometryTest.java | 6 +- 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/bds/source/java/ch/systemsx/cisd/bds/hcs/ChannelList.java b/bds/source/java/ch/systemsx/cisd/bds/hcs/ChannelList.java index a724bb74054..e91ce72eeda 100644 --- a/bds/source/java/ch/systemsx/cisd/bds/hcs/ChannelList.java +++ b/bds/source/java/ch/systemsx/cisd/bds/hcs/ChannelList.java @@ -18,6 +18,7 @@ package ch.systemsx.cisd.bds.hcs; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import ch.systemsx.cisd.bds.DataStructureException; @@ -38,7 +39,11 @@ public final class ChannelList implements IStorable public ChannelList(final List<Channel> channels) { - assert channels.size() > 0 : "At least one channel must be specified."; + assert channels != null && channels.size() > 0 : "At least one channel must be specified."; + if (new HashSet<Channel>(channels).size() != channels.size()) + { + throw new DataStructureException(String.format("Some duplicate channels in '%s'.", channels)); + } this.channels = channels; } diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/ChannelListTest.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/ChannelListTest.java index 8612226cba7..563da064929 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/ChannelListTest.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/ChannelListTest.java @@ -16,12 +16,68 @@ package ch.systemsx.cisd.bds.hcs; +import java.util.ArrayList; +import java.util.List; + +import org.testng.annotations.Test; +import static org.testng.AssertJUnit.*; + +import ch.systemsx.cisd.bds.DataStructureException; +import ch.systemsx.cisd.bds.storage.IDirectory; +import ch.systemsx.cisd.bds.storage.filesystem.NodeFactory; +import ch.systemsx.cisd.common.utilities.AbstractFileSystemTestCase; + /** * Test cases for corresponding {@link ChannelList} class. * * @author Christian Ribeaud */ -public final class ChannelListTest +public final class ChannelListTest extends AbstractFileSystemTestCase { + private final static ChannelList createChannelList() + { + final List<Channel> list = new ArrayList<Channel>(); + list.add(new Channel(1, 123)); + list.add(new Channel(2, 456)); + return new ChannelList(list); + } + + @Test + public final void testConstructor() + { + try + { + new ChannelList(null); + fail("Channel list can not be null."); + } catch (AssertionError ex) + { + } + try + { + new ChannelList(new ArrayList<Channel>()); + fail("Channel list can not be empty."); + } catch (AssertionError ex) + { + } + final List<Channel> list = new ArrayList<Channel>(); + list.add(new Channel(1, 123)); + list.add(new Channel(1, 456)); + try + { + new ChannelList(list); + fail("Duplicate channels are not allowed."); + } catch (DataStructureException e) + { + } + } + + @Test + public final void testSaveTo() + { + final ChannelList channelList = createChannelList(); + final IDirectory dir = NodeFactory.createDirectoryNode(workingDirectory); + channelList.saveTo(dir); + + } } \ No newline at end of file diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/PlateGeometryTest.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/PlateGeometryTest.java index 46169eda698..8559a453648 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/PlateGeometryTest.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/PlateGeometryTest.java @@ -72,8 +72,10 @@ public final class PlateGeometryTest extends AbstractFileSystemTestCase assertEquals(PlateGeometry.PLATE_GEOMETRY, geometryDir.getName()); files = geometryDir.listFiles(); assertEquals(2, files.length); - assertEquals(PlateGeometry.COLUMNS, files[0].getName()); - assertEquals(PlateGeometry.ROWS, files[1].getName()); + File file = files[0]; + assertTrue(file.getName().equals(Geometry.COLUMNS) || file.getName().equals(Geometry.ROWS)); + file = files[1]; + assertTrue(file.getName().equals(Geometry.COLUMNS) || file.getName().equals(Geometry.ROWS)); } @Test(dependsOnMethods = "testSaveTo") diff --git a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/WellGeometryTest.java b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/WellGeometryTest.java index 142d4f763a1..f8e55586654 100644 --- a/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/WellGeometryTest.java +++ b/bds/sourceTest/java/ch/systemsx/cisd/bds/hcs/WellGeometryTest.java @@ -72,8 +72,10 @@ public final class WellGeometryTest extends AbstractFileSystemTestCase assertEquals(WellGeometry.WELL_GEOMETRY, geometryDir.getName()); files = geometryDir.listFiles(); assertEquals(2, files.length); - assertEquals(WellGeometry.COLUMNS, files[0].getName()); - assertEquals(WellGeometry.ROWS, files[1].getName()); + File file = files[0]; + assertTrue(file.getName().equals(Geometry.COLUMNS) || file.getName().equals(Geometry.ROWS)); + file = files[1]; + assertTrue(file.getName().equals(Geometry.COLUMNS) || file.getName().equals(Geometry.ROWS)); } @Test(dependsOnMethods = "testSaveTo") -- GitLab