### Question:
ShardEntryGroup { public boolean addShard( final Shard shard ) { Preconditions.checkNotNull( "shard cannot be null", shard ); final int size = shards.size(); if ( size == 0 ) { addShardInternal( shard ); return true; } final Shard minShard = shards.get( size - 1 ); Preconditions.checkArgument( minShard.compareTo( shard ) > 0, "shard must be less than the current max" ); if ( !minShard.isCompacted() ) { addShardInternal( shard ); return true; } return false; } ShardEntryGroup( final long delta ); boolean addShard( final Shard shard ); Shard getMinShard(); Collection<Shard> getReadShards(); Collection<Shard> getWriteShards( long currentTime ); boolean isCompactionPending(); Shard getCompactionTarget(); int entrySize(); boolean shouldCompact( final long currentTime ); boolean isNew(final long currentTime); boolean canBeDeleted( final Shard shard ); @Override String toString();  }### Answer:
@Test public void multipleShardGroups() { final long delta = 10000; Shard firstShard = new Shard( 1000, 10000, false ); Shard secondShard = new Shard( 999, 9000, false ); Shard compactedShard1 = new Shard( 900, 8000, true ); Shard compactedShard2 = new Shard( 800, 7000, true ); ShardEntryGroup shardEntryGroup = new ShardEntryGroup( delta ); boolean result = shardEntryGroup.addShard( firstShard ); assertTrue( "Shard added", result ); result = shardEntryGroup.addShard( secondShard ); assertTrue( " Shard added", result ); result = shardEntryGroup.addShard( compactedShard1 ); assertTrue( "Shard added", result ); result = shardEntryGroup.addShard( compactedShard2 ); assertFalse( "Shouldn't add since it's compacted", result ); ShardEntryGroup secondGroup = new ShardEntryGroup( delta ); result = secondGroup.addShard( compactedShard2 ); assertTrue( "Added successfully", result ); }
@Test( expected = IllegalArgumentException.class ) public void failsInsertionOrder() { final long delta = 10000; Shard secondShard = new Shard( 20000, 10000, false ); Shard firstShard = new Shard( 10000, 10000, false ); Shard rootShard = new Shard( 0, 0, false ); ShardEntryGroup shardEntryGroup = new ShardEntryGroup( delta ); boolean result = shardEntryGroup.addShard( secondShard ); assertTrue( "Shard added", result ); result = shardEntryGroup.addShard( rootShard ); assertTrue( "Shard added", result ); shardEntryGroup.addShard( firstShard ); }
@Test public void shardEntryAddList() { final long delta = 10000; Shard highShard = new Shard( 30000, 1000, false ); Shard midShard = new Shard( 20000, 1000, true ); Shard lowShard = new Shard( 10000, 1000, false ); ShardEntryGroup shardEntryGroup = new ShardEntryGroup( delta ); boolean result = shardEntryGroup.addShard( highShard ); assertTrue( "Shard added", result ); result = shardEntryGroup.addShard( midShard ); assertTrue( "Shard added", result ); result = shardEntryGroup.addShard( lowShard ); assertFalse( "Shard added", result ); }