/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
- /*
- * All Sigmah code is released under the GNU General Public License v3
- * See COPYRIGHT.txt and LICENSE.txt.
- */
-
- package org.sigmah.client.dispatch.remote;
-
- import org.junit.Test;
- import org.sigmah.client.mock.NullAsyncCallback;
- import org.sigmah.shared.command.GetSchema;
-
- import java.util.Collection;
- import java.util.Collections;
- import java.util.List;
-
- import static org.hamcrest.CoreMatchers.equalTo;
- import static org.hamcrest.core.Is.is;
- import static org.junit.Assert.assertThat;
- import static org.junit.Assume.assumeThat;
- import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
-
- public class CommandRequestTest {
-
- @Test
- public void equalCommandsShouldBeMerged() {
-
- assumeThat(new GetSchema(), is(equalTo(new GetSchema())));
-
- CommandRequest firstCommand = new CommandRequest(new GetSchema(), null,
- new NullAsyncCallback());
- List<CommandRequest> pending = Collections.singletonList(firstCommand);
-
- CommandRequest secondRequest = new CommandRequest(new GetSchema(), null, new NullAsyncCallback());
-
- boolean merged = secondRequest.mergeSuccessfulInto(pending);
-
- assertThat("merged", merged, is(true));
- assertThat(firstCommand.getCallbacks(), hasItem(first(secondRequest.getCallbacks())));
-
- }
-
- private <T> T first(Collection<T> items) {
- return items.iterator().next();
- }
-
- }