PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/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 */
16package com.google.appengine.datanucleus.query;
17
18import com.google.apphosting.api.DatastorePb;
19
20import org.easymock.EasyMock;
21import org.easymock.IArgumentMatcher;
22
23/**
24 * @author Max Ross <max.ross@gmail.com>
25 */
26public class ChunkMatcher implements IArgumentMatcher {
27  private final Integer expectedChunkSize;
28
29  public ChunkMatcher(Integer expectedChunkSize) {
30    this.expectedChunkSize = expectedChunkSize;
31  }
32
33  public boolean matches(Object argument) {
34    DatastorePb.Query query = new DatastorePb.Query();
35    query.mergeFrom((byte[]) argument);
36    if (expectedChunkSize == null) {
37      return !query.hasCount();
38    }
39    return expectedChunkSize.equals(query.getCount());
40  }
41
42  public void appendTo(StringBuffer buffer) {
43    buffer.append("Chunk Matcher: " + expectedChunkSize);
44  }
45
46  public static byte[] eqChunkSize(Integer expectedChunkSize) {
47    EasyMock.reportMatcher(new ChunkMatcher(expectedChunkSize));
48    return null;
49  }
50}