/tests/com/google/appengine/datanucleus/query/ChunkMatcher.java

http://datanucleus-appengine.googlecode.com/ · Java · 50 lines · 25 code · 7 blank · 18 comment · 2 complexity · 35a877914310e54bbd4eb52362c4ba9a MD5 · raw file

  1. /*
  2. * Copyright (C) 2010 Google Inc
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.google.appengine.datanucleus.query;
  17. import com.google.apphosting.api.DatastorePb;
  18. import org.easymock.EasyMock;
  19. import org.easymock.IArgumentMatcher;
  20. /**
  21. * @author Max Ross <max.ross@gmail.com>
  22. */
  23. public class ChunkMatcher implements IArgumentMatcher {
  24. private final Integer expectedChunkSize;
  25. public ChunkMatcher(Integer expectedChunkSize) {
  26. this.expectedChunkSize = expectedChunkSize;
  27. }
  28. public boolean matches(Object argument) {
  29. DatastorePb.Query query = new DatastorePb.Query();
  30. query.mergeFrom((byte[]) argument);
  31. if (expectedChunkSize == null) {
  32. return !query.hasCount();
  33. }
  34. return expectedChunkSize.equals(query.getCount());
  35. }
  36. public void appendTo(StringBuffer buffer) {
  37. buffer.append("Chunk Matcher: " + expectedChunkSize);
  38. }
  39. public static byte[] eqChunkSize(Integer expectedChunkSize) {
  40. EasyMock.reportMatcher(new ChunkMatcher(expectedChunkSize));
  41. return null;
  42. }
  43. }