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 a724bb74054103dd175c4420d7a225abbe8cdf38..e91ce72eedaac15a476183b3310933bdfbff777c 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 8612226cba775a714250f14af914b3fb233c9dc3..563da06492953c915a2c2425e98620f84e3d4efe 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 46169eda69862af99680ae1cc4e89bb32c0e38cf..8559a453648adaad44f6322fbae556f594cd88f8 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 142d4f763a13589c17a6b4c661b12aaf7d9abad3..f8e55586654b10f007c6ea1d6f98cbd4bfb1479d 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")