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 import com.google.dart.engine.element.Element; |
| 18 import com.google.dart.engine.index.Location; |
| 19 |
| 20 import junit.framework.TestCase; |
| 21 |
| 22 import static org.mockito.Mockito.mock; |
| 23 import static org.mockito.Mockito.when; |
| 24 |
| 25 public class LocationDataTest extends TestCase { |
| 26 private AnalysisContext context = mock(AnalysisContext.class); |
| 27 private ElementCodec elementCodec = mock(ElementCodec.class); |
| 28 |
| 29 public void test_newFromData() throws Exception { |
| 30 Element element = mock(Element.class); |
| 31 when(elementCodec.decode(context, 0)).thenReturn(element); |
| 32 LocationData locationData = new LocationData(0, 1, 2); |
| 33 Location location = locationData.getLocation(context, elementCodec); |
| 34 assertEquals(element, location.getElement()); |
| 35 assertEquals(1, location.getOffset()); |
| 36 assertEquals(2, location.getLength()); |
| 37 } |
| 38 |
| 39 public void test_newFromObjects() throws Exception { |
| 40 // prepare Element |
| 41 Element element = mock(Element.class); |
| 42 when(elementCodec.encode(element)).thenReturn(42); |
| 43 when(elementCodec.decode(context, 42)).thenReturn(element); |
| 44 // create |
| 45 Location location = new Location(element, 1, 2); |
| 46 LocationData locationData = new LocationData(elementCodec, location); |
| 47 // touch hashCode() |
| 48 locationData.hashCode(); |
| 49 // equals() |
| 50 assertFalse(locationData.equals(null)); |
| 51 assertTrue(locationData.equals(locationData)); |
| 52 // getLocation() |
| 53 { |
| 54 Location newLocation = locationData.getLocation(context, elementCodec); |
| 55 assertEquals(element, newLocation.getElement()); |
| 56 assertEquals(1, newLocation.getOffset()); |
| 57 assertEquals(2, newLocation.getLength()); |
| 58 } |
| 59 // no Element - no Location |
| 60 { |
| 61 when(elementCodec.decode(context, 42)).thenReturn(null); |
| 62 Location newLocation = locationData.getLocation(context, elementCodec); |
| 63 assertNull(newLocation); |
| 64 } |
| 65 } |
| 66 } |
OLD | NEW |