PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/sigmah/src/test/java/org/sigmah/client/dispatch/remote/CommandRequestTest.java

http://sigma-h.googlecode.com/
Java | 46 lines | 28 code | 14 blank | 4 comment | 0 complexity | 197d539f9b5fa8aed2d4e6234aa71a15 MD5 | raw file
 1/*
 2 * All Sigmah code is released under the GNU General Public License v3
 3 * See COPYRIGHT.txt and LICENSE.txt.
 4 */
 5
 6package org.sigmah.client.dispatch.remote;
 7
 8import org.junit.Test;
 9import org.sigmah.client.mock.NullAsyncCallback;
10import org.sigmah.shared.command.GetSchema;
11
12import java.util.Collection;
13import java.util.Collections;
14import java.util.List;
15
16import static org.hamcrest.CoreMatchers.equalTo;
17import static org.hamcrest.core.Is.is;
18import static org.junit.Assert.assertThat;
19import static org.junit.Assume.assumeThat;
20import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
21
22public class CommandRequestTest {
23
24    @Test
25    public void equalCommandsShouldBeMerged() {
26
27        assumeThat(new GetSchema(), is(equalTo(new GetSchema())));
28
29        CommandRequest firstCommand = new CommandRequest(new GetSchema(), null,
30                new NullAsyncCallback());
31        List<CommandRequest> pending = Collections.singletonList(firstCommand);
32
33        CommandRequest secondRequest = new CommandRequest(new GetSchema(), null, new NullAsyncCallback());
34
35        boolean merged = secondRequest.mergeSuccessfulInto(pending);
36
37        assertThat("merged", merged, is(true));
38        assertThat(firstCommand.getCallbacks(), hasItem(first(secondRequest.getCallbacks())));
39
40    }
41
42    private <T> T first(Collection<T> items) {
43        return items.iterator().next();
44    }
45
46}