OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2014, the Dart project authors. |
| 3 * |
| 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u
se this file except |
| 5 * in compliance with the License. You may obtain a copy of the License at |
| 6 * |
| 7 * http://www.eclipse.org/legal/epl-v10.html |
| 8 * |
| 9 * Unless required by applicable law or agreed to in writing, software distribut
ed under the License |
| 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K
IND, either express |
| 11 * or implied. See the License for the specific language governing permissions a
nd limitations under |
| 12 * the License. |
| 13 */ |
| 14 package com.google.dart.engine.internal.index.file; |
| 15 |
| 16 import com.google.dart.engine.context.AnalysisContext; |
| 17 |
| 18 import junit.framework.TestCase; |
| 19 |
| 20 import static org.mockito.Mockito.mock; |
| 21 |
| 22 public class ContextCodecTest extends TestCase { |
| 23 private ContextCodec codec = new ContextCodec(); |
| 24 |
| 25 public void test_encode_decode() throws Exception { |
| 26 AnalysisContext contextA = mock(AnalysisContext.class); |
| 27 AnalysisContext contextB = mock(AnalysisContext.class); |
| 28 int idA = codec.encode(contextA); |
| 29 int idB = codec.encode(contextB); |
| 30 assertEquals(idA, codec.encode(contextA)); |
| 31 assertEquals(idB, codec.encode(contextB)); |
| 32 assertSame(contextA, codec.decode(idA)); |
| 33 assertSame(contextB, codec.decode(idB)); |
| 34 } |
| 35 |
| 36 public void test_remove() throws Exception { |
| 37 // encode |
| 38 { |
| 39 AnalysisContext context = mock(AnalysisContext.class); |
| 40 int id = codec.encode(context); |
| 41 assertEquals(0, id); |
| 42 assertSame(context, codec.decode(id)); |
| 43 // remove |
| 44 codec.removeContext(context); |
| 45 assertNull(codec.decode(id)); |
| 46 } |
| 47 // encode again |
| 48 { |
| 49 AnalysisContext context = mock(AnalysisContext.class); |
| 50 int id = codec.encode(context); |
| 51 assertEquals(1, id); |
| 52 assertSame(context, codec.decode(id)); |
| 53 } |
| 54 } |
| 55 } |
OLD | NEW |