/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. package org.sigmah.client.dispatch.remote;
  6. import org.junit.Test;
  7. import org.sigmah.client.mock.NullAsyncCallback;
  8. import org.sigmah.shared.command.GetSchema;
  9. import java.util.Collection;
  10. import java.util.Collections;
  11. import java.util.List;
  12. import static org.hamcrest.CoreMatchers.equalTo;
  13. import static org.hamcrest.core.Is.is;
  14. import static org.junit.Assert.assertThat;
  15. import static org.junit.Assume.assumeThat;
  16. import static org.junit.internal.matchers.IsCollectionContaining.hasItem;
  17. public class CommandRequestTest {
  18. @Test
  19. public void equalCommandsShouldBeMerged() {
  20. assumeThat(new GetSchema(), is(equalTo(new GetSchema())));
  21. CommandRequest firstCommand = new CommandRequest(new GetSchema(), null,
  22. new NullAsyncCallback());
  23. List<CommandRequest> pending = Collections.singletonList(firstCommand);
  24. CommandRequest secondRequest = new CommandRequest(new GetSchema(), null, new NullAsyncCallback());
  25. boolean merged = secondRequest.mergeSuccessfulInto(pending);
  26. assertThat("merged", merged, is(true));
  27. assertThat(firstCommand.getCallbacks(), hasItem(first(secondRequest.getCallbacks())));
  28. }
  29. private <T> T first(Collection<T> items) {
  30. return items.iterator().next();
  31. }
  32. }