PageRenderTime 31ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/netbeans-7.3/java.editor/test/qa-functional/src/org/netbeans/test/java/editor/codegeneration/GenerateCodeTestCase.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 140 lines | 80 code | 26 blank | 34 comment | 5 complexity | ddeb0e8934363412c97c0681dc20523c MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * Contributor(s):
  28. *
  29. * Portions Copyrighted 2007 Sun Microsystems, Inc.
  30. */
  31. package org.netbeans.test.java.editor.codegeneration;
  32. import java.util.regex.Matcher;
  33. import java.util.regex.Pattern;
  34. import org.netbeans.test.java.editor.lib.EditorTestCase;
  35. import org.netbeans.jellytools.EditorOperator;
  36. import org.netbeans.jemmy.operators.JEditorPaneOperator;
  37. /**
  38. *
  39. * @author Jiri Prox
  40. */
  41. public class GenerateCodeTestCase extends EditorTestCase {
  42. public GenerateCodeTestCase(String testMethodName) {
  43. super(testMethodName);
  44. }
  45. public static String getJDKVersionCode() {
  46. String specVersion = System.getProperty("java.version");
  47. if (specVersion.startsWith("1.4")) {
  48. return "jdk14";
  49. }
  50. if (specVersion.startsWith("1.5")) {
  51. return "jdk15";
  52. }
  53. if (specVersion.startsWith("1.6")) {
  54. return "jdk16";
  55. }
  56. throw new IllegalStateException("Specification version: " + specVersion + " not recognized.");
  57. }
  58. private boolean isWin() {
  59. return System.getProperty("os.name").contains("Windows");
  60. }
  61. @Override
  62. protected void setUp() throws Exception {
  63. super.setUp();
  64. openProject("java_editor_test");
  65. }
  66. @Override
  67. protected void tearDown() throws Exception {
  68. super.tearDown();
  69. }
  70. protected void waitAndCompare(String expected) {
  71. waitMaxMilisForValue(1500, new EditorValueResolver(expected), Boolean.TRUE);
  72. if (!editor.getText().contains(expected)) {
  73. System.out.println("Text pattern:");
  74. System.out.println(expected);
  75. System.out.println("-------------------");
  76. System.out.println(editor.getText());
  77. }
  78. assertTrue("Expected code is not inserted", editor.getText().contains(expected));
  79. }
  80. protected void waitAndCompareRegexp(String regexp) {
  81. Pattern p = Pattern.compile(regexp, Pattern.DOTALL);
  82. waitMaxMilisForValue(1500, new EditorValueResolverRegexp(p), Boolean.TRUE);
  83. if (!p.matcher(editor.getText()).matches()) {
  84. System.out.println("Regular expresion pattern:");
  85. System.out.println(regexp);
  86. System.out.println("-------------------");
  87. System.out.println(editor.getText());
  88. }
  89. assertTrue("Expected code is not inserted", p.matcher(editor.getText()).matches());
  90. }
  91. protected EditorOperator editor;
  92. protected JEditorPaneOperator txtOper;
  93. protected class EditorValueResolver implements ValueResolver {
  94. private String text;
  95. public EditorValueResolver(String text) {
  96. this.text = text;
  97. }
  98. public Object getValue() {
  99. return editor.getText().contains(text);
  100. }
  101. }
  102. protected class EditorValueResolverRegexp implements ValueResolver {
  103. private Pattern pattern;
  104. public EditorValueResolverRegexp(String text) {
  105. }
  106. private EditorValueResolverRegexp(Pattern pattern) {
  107. this.pattern = pattern;
  108. }
  109. public Object getValue() {
  110. Matcher matcher = pattern.matcher(editor.getText());
  111. return matcher.matches();
  112. }
  113. }
  114. }