| /* |
| * 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.assertNull; |
| import static org.junit.Assert.assertThat; |
| |
| import static com.google.eclipse.protobuf.junit.core.UnitTestModule.unitTestModule; |
| import static com.google.eclipse.protobuf.junit.core.XtextRule.overrideRuntimeModuleWith; |
| |
| import org.junit.Rule; |
| import org.junit.Test; |
| |
| import com.google.eclipse.protobuf.junit.core.XtextRule; |
| import com.google.eclipse.protobuf.protobuf.Enum; |
| import com.google.eclipse.protobuf.protobuf.MessageField; |
| import com.google.inject.Inject; |
| |
| /** |
| * Tests for <code>{@link MessageFields#enumTypeOf(MessageField)}</code>. |
| * |
| * @author alruiz@google.com (Alex Ruiz) |
| */ |
| public class MessageFields_enumTypeOf_Test { |
| @Rule public XtextRule xtext = overrideRuntimeModuleWith(unitTestModule()); |
| |
| @Inject private MessageFields fields; |
| |
| // syntax = "proto2"; |
| // |
| // enum PhoneType { |
| // MOBILE = 0; |
| // HOME = 1; |
| // WORK = 2; |
| // } |
| // |
| // message PhoneNumber { |
| // optional PhoneType type = 1; |
| // } |
| @Test public void should_return_enum_if_field_type_is_enum() { |
| MessageField field = xtext.find("type", MessageField.class); |
| Enum anEnum = fields.enumTypeOf(field); |
| assertThat(anEnum.getName(), equalTo("PhoneType")); |
| } |
| |
| // syntax = "proto2"; |
| // |
| // message Person { |
| // optional string name = 1; |
| // } |
| @Test public void should_return_null_if_field_type_is_not_enum() { |
| MessageField field = xtext.find("name", MessageField.class); |
| assertNull(fields.enumTypeOf(field)); |
| } |
| } |