@@ -0,0 +1,1426 @@
+/*%0A * @(#)BaseHasShardIdListTest.java 2013%E5%B9%B48%E6%9C%8830%E6%97%A5 %E4%B8%8B%E5%8D%8822:33:33%0A *%0A * Copyright (c) 2011-2013 Makersoft.org all rights reserved.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A *%0A */%0Apackage org.makersoft.shards.unit;%0A%0Aimport java.util.List;%0A%0Aimport org.junit.Assert;%0Aimport org.junit.Test;%0Aimport org.makersoft.shards.BaseHasShardIdList;%0Aimport org.makersoft.shards.ShardId;%0Aimport org.makersoft.shards.utils.Lists;%0A%0A/**%0A * @author Feng Kuok%0A */%0Apublic class BaseHasShardIdListTest %7B%0A%0A%09@Test%0A%09public void testShardIdListUnmodifiable() %7B%0A%09%09List%3CShardId%3E shardIdList = null;%0A%09%09try %7B%0A%09%09%09new MyBaseHasShardIdList(shardIdList);%0A%09%09%09Assert.fail(%22expected npe%22);%0A%09%09%7D catch (IllegalArgumentException npe) %7B%0A%09%09%09// good%0A%09%09%7D%0A%09%09shardIdList = Lists.newArrayList();%0A%09%09try %7B%0A%09%09%09new MyBaseHasShardIdList(shardIdList);%0A%09%09%09Assert.fail(%22expected iae%22);%0A%09%09%7D catch (IllegalArgumentException iae) %7B%0A%09%09%09// good%0A%09%09%7D%0A%09%09shardIdList.add(new ShardId(0));%0A%09%09BaseHasShardIdList bhsil = new MyBaseHasShardIdList(shardIdList);%0A%09%09ShardId anotherId = new ShardId(1);%0A%09%09shardIdList.add(anotherId);%0A%09%09// demonstrate that external changes to the list that was passed in%0A%09%09// aren't reflected inside the object%0A%09%09Assert.assertFalse(bhsil.getShardIds().contains(anotherId));%0A%09%7D%0A%0A%09private static final class MyBaseHasShardIdList extends BaseHasShardIdList %7B%0A%0A%09%09protected MyBaseHasShardIdList(List%3CShardId%3E shardIds) %7B%0A%09%09%09super(shardIds);%0A%09%09%7D%0A%09%7D%0A%7D%0A

add unit test