Adding unit tests for com.google.eclipse.protobuf.
diff --git a/com.google.eclipse.protobuf.test/.classpath b/com.google.eclipse.protobuf.test/.classpath new file mode 100644 index 0000000..64c5e31 --- /dev/null +++ b/com.google.eclipse.protobuf.test/.classpath
@@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath>
diff --git a/com.google.eclipse.protobuf.test/.project b/com.google.eclipse.protobuf.test/.project new file mode 100644 index 0000000..55e19bf --- /dev/null +++ b/com.google.eclipse.protobuf.test/.project
@@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>com.google.eclipse.protobuf.test</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
diff --git a/com.google.eclipse.protobuf.test/.settings/org.eclipse.jdt.core.prefs b/com.google.eclipse.protobuf.test/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..f6d1a9a --- /dev/null +++ b/com.google.eclipse.protobuf.test/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@ +#Mon Apr 25 12:58:25 PDT 2011 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5
diff --git a/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF new file mode 100644 index 0000000..d9ceabf --- /dev/null +++ b/com.google.eclipse.protobuf.test/META-INF/MANIFEST.MF
@@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Tests for com.google.eclipse.protobuf +Bundle-SymbolicName: com.google.eclipse.protobuf.test +Bundle-Version: 1.0.0 +Bundle-Vendor: Google +Fragment-Host: com.google.eclipse.protobuf;bundle-version="1.0.0" +Require-Bundle: org.junit;bundle-version="4.8.1", + org.junit.source;bundle-version="4.8.1", + org.eclipse.xtext.junit;bundle-version="2.0.0", + org.eclipse.xtext.junit4;bundle-version="2.0.0", + com.google.eclipse.protobuf.junit;bundle-version="1.0.0" +Bundle-RequiredExecutionEnvironment: J2SE-1.5
diff --git a/com.google.eclipse.protobuf.test/build.properties b/com.google.eclipse.protobuf.test/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/com.google.eclipse.protobuf.test/build.properties
@@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .
diff --git a/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java new file mode 100644 index 0000000..facba74 --- /dev/null +++ b/com.google.eclipse.protobuf.test/src/com/google/eclipse/protobuf/naming/ProtobufQualifiedNameProvider_getFullyQualifiedName_Test.java
@@ -0,0 +1,85 @@ +/* + * 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.naming; + +import static com.google.eclipse.protobuf.junit.Finder.*; +import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertThat; + +import org.eclipse.xtext.naming.IQualifiedNameProvider; +import org.eclipse.xtext.naming.QualifiedName; +import org.junit.*; + +import com.google.eclipse.protobuf.junit.XtextRule; +import com.google.eclipse.protobuf.protobuf.*; + +/** + * Tests for <code>{@link ProtobufQualifiedNameProvider}</code>. + * + * @author alruiz@google.com (Alex Ruiz) + */ +public class ProtobufQualifiedNameProvider_getFullyQualifiedName_Test { + + @Rule public XtextRule xtext = new XtextRule(); + + private ProtobufQualifiedNameProvider provider; + + @Before public void setUp() { + provider = (ProtobufQualifiedNameProvider) xtext.getInstanceOf(IQualifiedNameProvider.class); + } + + @Test public void should_include_existing_package_name_as_part_of_message_FQN() { + StringBuilder proto = new StringBuilder(); + proto.append("package fqn.test; ") + .append(" ") + .append("message Person { ") + .append(" optional string name = 1;") + .append("} "); + Protobuf root = xtext.parse(proto); + Message person = findMessage("Person", root); + QualifiedName fqn = provider.getFullyQualifiedName(person); + assertThat(fqn.toString(), equalTo("fqn.test.Person")); + } + + @Test public void should_include_existing_package_name_as_part_of_property_FQN() { + StringBuilder proto = new StringBuilder(); + proto.append("package fqn.test; ") + .append(" ") + .append("message Person { ") + .append(" optional string name = 1;") + .append("} "); + Protobuf root = xtext.parse(proto); + Property name = findProperty("name", root); + QualifiedName fqn = provider.getFullyQualifiedName(name); + assertThat(fqn.toString(), equalTo("fqn.test.Person.name")); + } + + + @Test public void should_not_include_package_name_as_part_of_message_FQN_if_package_is_not_specified() { + StringBuilder proto = new StringBuilder(); + proto.append("message Person { ") + .append(" optional string name = 1;") + .append("} "); + Protobuf root = xtext.parse(proto); + Message person = findMessage("Person", root); + QualifiedName fqn = provider.getFullyQualifiedName(person); + assertThat(fqn.toString(), equalTo("Person")); + } + + @Test public void should_not_include_package_name_as_part_of_property_FQN_if_package_is_not_specified() { + StringBuilder proto = new StringBuilder(); + proto.append("message Person { ") + .append(" optional string name = 1;") + .append("} "); + Protobuf root = xtext.parse(proto); + Property name = findProperty("name", root); + QualifiedName fqn = provider.getFullyQualifiedName(name); + assertThat(fqn.toString(), equalTo("Person.name")); + } +}