In progress: [Issue 157] Groups should be considered Types.
Added more tests.
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexFeatureOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexFeatureOf_Test.java
new file mode 100644
index 0000000..cf39f97
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexFeatureOf_Test.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.model.util;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import com.google.eclipse.protobuf.protobuf.*;
+
+import org.eclipse.emf.ecore.EStructuralFeature;
+import org.junit.*;
+import static com.google.eclipse.protobuf.protobuf.ProtobufPackage.Literals.*;
+
+/**
+ * Tests for <code>{@link IndexedElements#indexFeatureOf(IndexedElement)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class IndexedElements_indexFeatureOf_Test {
+
+ private static IndexedElements indexedElements;
+
+ @BeforeClass public static void setUpOnce() {
+ indexedElements = new IndexedElements();
+ }
+
+ @Test public void should_return_name_of_Property() {
+ Property p = mock(Property.class);
+ EStructuralFeature expected = PROPERTY__INDEX;
+ assertThat(indexedElements.indexFeatureOf(p), equalTo(expected));
+ }
+
+ @Test public void should_return_name_of_Group() {
+ Group g = mock(Group.class);
+ EStructuralFeature expected = GROUP__INDEX;
+ assertThat(indexedElements.indexFeatureOf(g), equalTo(expected));
+ }
+
+ @Test public void should_return_null_if_IndexedElement_is_null() {
+ assertNull(indexedElements.indexFeatureOf(null));
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexOf_Test.java
new file mode 100644
index 0000000..98c76ee
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_indexOf_Test.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.model.util;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import com.google.eclipse.protobuf.protobuf.*;
+
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link IndexedElements#indexOf(IndexedElement)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class IndexedElements_indexOf_Test {
+
+ private static IndexedElements indexedElements;
+
+ @BeforeClass public static void setUpOnce() {
+ indexedElements = new IndexedElements();
+ }
+
+ @Test public void should_return_name_of_Property() {
+ Property p = mock(Property.class);
+ when(p.getIndex()).thenReturn(6L);
+ assertThat(indexedElements.indexOf(p), equalTo(6L));
+ verify(p).getIndex();
+ }
+
+ @Test public void should_return_name_of_Group() {
+ Group g = mock(Group.class);
+ when(g.getIndex()).thenReturn(8L);
+ assertThat(indexedElements.indexOf(g), equalTo(8L));
+ verify(g).getIndex();
+ }
+
+ @Test public void should_return_MIN_VALUE_if_IndexedElement_is_null() {
+ assertThat(indexedElements.indexOf(null), equalTo(Long.MIN_VALUE));
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_nameOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_nameOf_Test.java
new file mode 100644
index 0000000..ed939bf
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_nameOf_Test.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.model.util;
+
+import static org.hamcrest.core.IsEqual.equalTo;
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import com.google.eclipse.protobuf.protobuf.*;
+
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link IndexedElements#nameOf(IndexedElement)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class IndexedElements_nameOf_Test {
+
+ private static IndexedElements indexedElements;
+
+ @BeforeClass public static void setUpOnce() {
+ indexedElements = new IndexedElements();
+ }
+
+ @Test public void should_return_name_of_Property() {
+ Property p = mock(Property.class);
+ when(p.getName()).thenReturn("foo");
+ assertThat(indexedElements.nameOf(p), equalTo("foo"));
+ verify(p).getName();
+ }
+
+ @Test public void should_return_name_of_Group() {
+ Group g = mock(Group.class);
+ when(g.getName()).thenReturn("foo");
+ assertThat(indexedElements.nameOf(g), equalTo("foo"));
+ verify(g).getName();
+ }
+
+ @Test public void should_return_null_if_IndexedElement_is_null() {
+ assertNull(indexedElements.nameOf(null));
+ }
+}
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_setIndexOf_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_setIndexOf_Test.java
new file mode 100644
index 0000000..3b72ac9
--- /dev/null
+++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/model/util/IndexedElements_setIndexOf_Test.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ *
+ * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
+ * Public License v1.0 which accompanies this distribution, and is available at
+ *
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.model.util;
+
+import static org.mockito.Mockito.*;
+
+import com.google.eclipse.protobuf.protobuf.*;
+
+import org.junit.*;
+
+/**
+ * Tests for <code>{@link IndexedElements#setIndexTo(IndexedElement, long)}</code>
+ *
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class IndexedElements_setIndexOf_Test {
+
+ private static IndexedElements indexedElements;
+
+ @BeforeClass public static void setUpOnce() {
+ indexedElements = new IndexedElements();
+ }
+
+ @Test public void should_return_name_of_Property() {
+ Property p = mock(Property.class);
+ indexedElements.setIndexTo(p, 6L);
+ verify(p).setIndex(6L);
+ }
+
+ @Test public void should_return_name_of_Group() {
+ Group g = mock(Group.class);
+ indexedElements.setIndexTo(g, 8L);
+ verify(g).setIndex(8L);
+ }
+}
diff --git a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
index ed4cab1..dca138d 100644
--- a/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
+++ b/com.google.eclipse.protobuf/src/com/google/eclipse/protobuf/model/util/IndexedElements.java
@@ -23,8 +23,6 @@
* Utility methods related to <code>{@link IndexedElement}</code>s.
*
* @author alruiz@google.com (Alex Ruiz)
- *
- * TODO test
*/
@Singleton
public class IndexedElements {
@@ -43,11 +41,11 @@
/**
* Returns the name of the given <code>{@link IndexedElement}</code>.
* @param e the given {@code IndexedElement}.
- * @return the name of the given {@code IndexedElement}, or -1 if the given {@code IndexedElement} is
- * {@code null}..
+ * @return the name of the given {@code IndexedElement}, or {@code Long.MIN_VALUE} if the given {@code IndexedElement}
+ * is {@code null}..
*/
public long indexOf(IndexedElement e) {
- if (e == null) return -1;
+ if (e == null) return Long.MIN_VALUE;
return (e instanceof Group) ? ((Group) e).getIndex() : ((Property) e).getIndex();
}