PageRenderTime 55ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/DiscriminatorColumnLineParserTest.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 209 lines | 144 code | 20 blank | 45 comment | 8 complexity | f5a91bace4c0a47d9da96e3d01667da4 MD5 | raw file
  1. package org.netbeans.modules.php.doctrine2.annotations.orm.parser;
  2. import java.util.Map;
  3. import org.netbeans.junit.NbTestCase;
  4. import org.netbeans.modules.csl.api.OffsetRange;
  5. import org.netbeans.modules.php.spi.annotation.AnnotationLineParser;
  6. import org.netbeans.modules.php.spi.annotation.AnnotationParsedLine;
  7. import org.netbeans.modules.php.spi.annotation.AnnotationParsedLine.ParsedLine;
  8. /*
  9. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  10. *
  11. * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
  12. *
  13. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  14. * Other names may be trademarks of their respective owners.
  15. *
  16. * The contents of this file are subject to the terms of either the GNU
  17. * General Public License Version 2 only ("GPL") or the Common
  18. * Development and Distribution License("CDDL") (collectively, the
  19. * "License"). You may not use this file except in compliance with the
  20. * License. You can obtain a copy of the License at
  21. * http://www.netbeans.org/cddl-gplv2.html
  22. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  23. * specific language governing permissions and limitations under the
  24. * License. When distributing the software, include this License Header
  25. * Notice in each file and include the License file at
  26. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  27. * particular file as subject to the "Classpath" exception as provided
  28. * by Oracle in the GPL Version 2 section of the License file that
  29. * accompanied this code. If applicable, add the following below the
  30. * License Header, with the fields enclosed by brackets [] replaced by
  31. * your own identifying information:
  32. * "Portions Copyrighted [year] [name of copyright owner]"
  33. *
  34. * If you wish your version of this file to be governed by only the CDDL
  35. * or only the GPL Version 2, indicate your decision by adding
  36. * "[Contributor] elects to include this software in this distribution
  37. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  38. * single choice of license, a recipient has the option to distribute
  39. * your version of this file under either the CDDL, the GPL Version 2 or
  40. * to extend the choice of license to its licensees as provided above.
  41. * However, if you add GPL Version 2 code and therefore, elected the GPL
  42. * Version 2 license, then the option applies only if the new code is
  43. * made subject to such option by the copyright holder.
  44. *
  45. * Contributor(s):
  46. *
  47. * Portions Copyrighted 2012 Sun Microsystems, Inc.
  48. */
  49. /**
  50. *
  51. * @author Ondrej Brejla <obrejla@netbeans.org>
  52. */
  53. public class DiscriminatorColumnLineParserTest extends NbTestCase {
  54. private ParameterizedAnnotationLineParser parser;
  55. public DiscriminatorColumnLineParserTest(String name) {
  56. super(name);
  57. }
  58. @Override
  59. protected void setUp() throws Exception {
  60. super.setUp();
  61. this.parser = new ParameterizedAnnotationLineParser();
  62. }
  63. public void testIsAnnotationParser() throws Exception {
  64. assertTrue(parser instanceof AnnotationLineParser);
  65. }
  66. public void testReturnValueIsDiscriminatorColumnParsedLine_01() throws Exception {
  67. assertTrue(parser.parse("DiscriminatorColumn") instanceof ParsedLine);
  68. }
  69. public void testReturnValueIsDiscriminatorColumnParsedLine_02() throws Exception {
  70. assertTrue(parser.parse("Annotations\\DiscriminatorColumn") instanceof ParsedLine);
  71. }
  72. public void testReturnValueIsDiscriminatorColumnParsedLine_03() throws Exception {
  73. assertTrue(parser.parse("\\Foo\\Bar\\DiscriminatorColumn") instanceof ParsedLine);
  74. }
  75. public void testReturnValueIsDiscriminatorColumnParsedLine_04() throws Exception {
  76. assertTrue(parser.parse("Annotations\\DiscriminatorColumn(type=\"string\", length=32)") instanceof ParsedLine);
  77. }
  78. public void testReturnValueIsNull() throws Exception {
  79. assertNull(parser.parse("DiscriminatorColumns"));
  80. }
  81. public void testValidUseCase_01() throws Exception {
  82. AnnotationParsedLine parsedLine = parser.parse("DiscriminatorColumn");
  83. assertEquals("DiscriminatorColumn", parsedLine.getName());
  84. assertEquals("", parsedLine.getDescription());
  85. Map<OffsetRange, String> types = parsedLine.getTypes();
  86. for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
  87. OffsetRange offsetRange = entry.getKey();
  88. String value = entry.getValue();
  89. assertEquals(0, offsetRange.getStart());
  90. assertEquals(19, offsetRange.getEnd());
  91. assertEquals("DiscriminatorColumn", value);
  92. }
  93. }
  94. public void testValidUseCase_02() throws Exception {
  95. AnnotationParsedLine parsedLine = parser.parse("DiscriminatorColumn ");
  96. assertEquals("DiscriminatorColumn", parsedLine.getName());
  97. assertEquals("", parsedLine.getDescription());
  98. Map<OffsetRange, String> types = parsedLine.getTypes();
  99. for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
  100. OffsetRange offsetRange = entry.getKey();
  101. String value = entry.getValue();
  102. assertEquals(0, offsetRange.getStart());
  103. assertEquals(19, offsetRange.getEnd());
  104. assertEquals("DiscriminatorColumn", value);
  105. }
  106. }
  107. public void testValidUseCase_03() throws Exception {
  108. AnnotationParsedLine parsedLine = parser.parse("DiscriminatorColumn\t\t ");
  109. assertEquals("DiscriminatorColumn", parsedLine.getName());
  110. assertEquals("", parsedLine.getDescription());
  111. Map<OffsetRange, String> types = parsedLine.getTypes();
  112. for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
  113. OffsetRange offsetRange = entry.getKey();
  114. String value = entry.getValue();
  115. assertEquals(0, offsetRange.getStart());
  116. assertEquals(19, offsetRange.getEnd());
  117. assertEquals("DiscriminatorColumn", value);
  118. }
  119. }
  120. public void testValidUseCase_04() throws Exception {
  121. AnnotationParsedLine parsedLine = parser.parse("DiscriminatorColumn(type=\"string\", length=32)");
  122. assertEquals("DiscriminatorColumn", parsedLine.getName());
  123. assertEquals("(type=\"string\", length=32)", parsedLine.getDescription());
  124. Map<OffsetRange, String> types = parsedLine.getTypes();
  125. assertNotNull(types);
  126. for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
  127. OffsetRange offsetRange = entry.getKey();
  128. String value = entry.getValue();
  129. assertEquals(0, offsetRange.getStart());
  130. assertEquals(19, offsetRange.getEnd());
  131. assertEquals("DiscriminatorColumn", value);
  132. }
  133. }
  134. public void testValidUseCase_05() throws Exception {
  135. AnnotationParsedLine parsedLine = parser.parse("Annotations\\DiscriminatorColumn(type=\"string\", length=32) \t");
  136. assertEquals("DiscriminatorColumn", parsedLine.getName());
  137. assertEquals("(type=\"string\", length=32)", parsedLine.getDescription());
  138. Map<OffsetRange, String> types = parsedLine.getTypes();
  139. assertNotNull(types);
  140. for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
  141. OffsetRange offsetRange = entry.getKey();
  142. String value = entry.getValue();
  143. assertEquals(0, offsetRange.getStart());
  144. assertEquals(31, offsetRange.getEnd());
  145. assertEquals("Annotations\\DiscriminatorColumn", value);
  146. }
  147. }
  148. public void testValidUseCase_06() throws Exception {
  149. AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\DiscriminatorColumn(type=\"string\", length=32) \t");
  150. assertEquals("DiscriminatorColumn", parsedLine.getName());
  151. assertEquals("(type=\"string\", length=32)", parsedLine.getDescription());
  152. Map<OffsetRange, String> types = parsedLine.getTypes();
  153. assertNotNull(types);
  154. for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
  155. OffsetRange offsetRange = entry.getKey();
  156. String value = entry.getValue();
  157. assertEquals(0, offsetRange.getStart());
  158. assertEquals(28, offsetRange.getEnd());
  159. assertEquals("\\Foo\\Bar\\DiscriminatorColumn", value);
  160. }
  161. }
  162. public void testValidUseCase_07() throws Exception {
  163. AnnotationParsedLine parsedLine = parser.parse("discriminatorcolumn");
  164. assertEquals("DiscriminatorColumn", parsedLine.getName());
  165. assertEquals("", parsedLine.getDescription());
  166. Map<OffsetRange, String> types = parsedLine.getTypes();
  167. for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
  168. OffsetRange offsetRange = entry.getKey();
  169. String value = entry.getValue();
  170. assertEquals(0, offsetRange.getStart());
  171. assertEquals(19, offsetRange.getEnd());
  172. assertEquals("discriminatorcolumn", value);
  173. }
  174. }
  175. public void testValidUseCase_08() throws Exception {
  176. AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\discriminatorcolumn(type=\"string\", length=32) \t");
  177. assertEquals("DiscriminatorColumn", parsedLine.getName());
  178. assertEquals("(type=\"string\", length=32)", parsedLine.getDescription());
  179. Map<OffsetRange, String> types = parsedLine.getTypes();
  180. assertNotNull(types);
  181. for (Map.Entry<OffsetRange, String> entry : types.entrySet()) {
  182. OffsetRange offsetRange = entry.getKey();
  183. String value = entry.getValue();
  184. assertEquals(0, offsetRange.getStart());
  185. assertEquals(28, offsetRange.getEnd());
  186. assertEquals("\\Foo\\Bar\\discriminatorcolumn", value);
  187. }
  188. }
  189. }