Exemplo n.º 1
0
  private void end(StringBuilder ans, Pretty pretty, String indent) {
    if (endEncloser == null) return;
    if (!pretty.pretty) ans.append(endEncloser);
    else {
      Utilities.assureEndsWithNewLine(ans);
      ans.append(indent + endEncloser);
      if (pretty.comments && endComment.length() > 0) ans.append("#" + endComment);

      Utilities.assureEndsWithNewLine(ans);
    }
  }
Exemplo n.º 2
0
  /**
   * Returns the TabularData
   *
   * @return TabularData containing the rows corresponding the NetworkTable
   */
  public TabularData getNetworkTable() {
    try {
      if (table != null)
        return Utilities.getTabularData(this, indexNames, table, instrClassName, null);
      else if (vec != null)
        return Utilities.getTabularData(this, indexNames, vec, instrClassName, null);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return null;
  }
Exemplo n.º 3
0
  /**
   * Returns the TabularData
   *
   * @return TabularData containing the rows corresponding the AlarmTable
   */
  public TabularData getAlarmTable() {

    // User code starts here
    if (true) {
      return getTable();
    }
    // User code ends here

    try {
      if (table != null)
        return Utilities.getTabularData(this, indexNames, table, instrClassName, null);
      else if (vec != null)
        return Utilities.getTabularData(this, indexNames, vec, instrClassName, null);
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return null;
  }
Exemplo n.º 4
0
 void doKids(StringBuilder ans, Pretty pretty, String indent) {
   if (kids == null) return;
   for (Rope kid : kids) {
     if (!pretty.pretty) {
       kid.toString(ans, pretty, "");
     } else {
       kid.toString(ans, pretty, indent + getKidIndentIncrement(kid, pretty));
       Utilities.assureEndsWithNewLine(ans);
     }
   }
 }
Exemplo n.º 5
0
 private void start(StringBuilder ans, Pretty pretty, String indent) {
   if (startEncloser == null) return;
   if (!pretty.pretty) {
     ans.append(startEncloser);
   } else {
     String comment;
     if (pretty.comments && startComment.length() > 0) comment = " #" + startComment;
     else comment = "";
     ans.append(indent + startEncloser + comment);
     Utilities.assureEndsWithNewLine(ans);
   }
 }
Exemplo n.º 6
0
  /**
   * Sets up the <em>startup</em> {@linkplain Mock mocks} defined in one or more mock classes, just
   * like {@link #setUpMocks(Object...)} does for regular mock classes. The difference is in the
   * lifetime of the mocks, which will last to the end of the test run. Consequently, this method
   * should only be called once, before the first test begins execution. One way to achieve this is
   * to put the call in the static initializer of a common base class extended by all test classes
   * in the suite. Another way is by configuring what happens at startup through external means.
   *
   * <p>There are three ways to set up mock classes at startup time:
   *
   * <ol>
   *   <li>Define a value for the "<code>jmockit-mocks</code>" system property, as a comma-separated
   *       list of fully qualified class names.
   *   <li>Add a custom "<code>jmockit.properties</code>" file to the classpath, with an entry for
   *       the "<code>jmockit-mocks</code>" (or just "<code>mocks</code>") property.
   *   <li>Specify the "<code>-javaagent:jmockit.jar=&lt;agentArgs></code>" JVM argument, with "
   *       <code>agentArgs</code>" containing one or more mock class names, separated by semicolons
   *       if more than one.
   * </ol>
   *
   * Note that option two above makes it possible to package a whole set of reusable mock classes in
   * a jar file, provided it contains a suitable <code>jmockit.properties</code> file. By simply
   * adding the jar to the classpath <em>before</em> <code>jmockit.jar</code>, the specified mock
   * classes will be loaded and applied automatically on every test run, as soon as JMockit itself
   * gets initialized.
   *
   * @param mockClassesOrInstances one or more mock classes (either <code>Class</code> literals or
   *     fully qualified class names) or instances of mock classes
   * @throws IllegalArgumentException if a given mock class fails to specify the corresponding real
   *     class using the {@code @MockClass(realClass = ...)} annotation; or if a mock class defines
   *     a mock method for which no corresponding real method or constructor exists in the real
   *     class; or if the real method matching a mock method is {@code abstract}
   * @see <a
   *     href="http://code.google.com/p/jmockit/source/browse/trunk/main/test/mockit/MockAnnotationsTest.java#465">
   *     Example</a>
   *     <p>In the Tutorial: <a
   *     href="http://jmockit.googlecode.com/svn/trunk/www/tutorial/UsingMocksAndStubs.html">Using
   *     mocks and stubs over entire test classes and suites</a>
   */
  public static void setUpStartupMocks(Object... mockClassesOrInstances) {
    for (Object mockClassOrInstance : mockClassesOrInstances) {
      Class<?> mockClass;
      Object mock;

      if (mockClassOrInstance instanceof Class<?>) {
        mockClass = (Class<?>) mockClassOrInstance;
        mock = null;
      } else if (mockClassOrInstance instanceof String) {
        String className = ((String) mockClassOrInstance).trim();
        if (className.length() == 0) continue;
        mockClass = Utilities.loadClass(className);
        mock = null;
      } else {
        mockClass = mockClassOrInstance.getClass();
        mock = mockClassOrInstance;
      }

      new MockClassSetup(mock, mockClass).setUpStartupMock();
    }
  }
Exemplo n.º 7
0
 /**
  * Creates a {@link Proxy} implementation for a given set of interface types. In this created
  * class all methods will be empty, with return values for non-void methods being the appropriate
  * default value ({@literal 0} for {@code int}, {@literal null} for a reference type, and so on).
  *
  * <p>The {@code equals}, {@code hashCode}, and {@code toString} methods inherited from {@code
  * java.lang.Object} are overridden with an appropriate implementation in each case: {@code
  * equals} is implemented by comparing the two object references (the proxy instance and the
  * method argument) for equality; {@code hashCode} is implemented to return the identity hash code
  * for the proxy instance; and {@code toString} returns the standard string representation that
  * {@code Object#toString} would have returned.
  *
  * <p>This method is just a convenience for some uses of the <em>Mockups</em> API. In <em>JMockit
  * Expectations</em> in particular, mocked instances will be automatically created and assigned to
  * any mock fields or parameters.
  *
  * @param interfacesToBeProxied one or more {@code Type} objects, each of which can be a {@code
  *     Class} object for an interface, a {@link ParameterizedType} whose raw type is an interface,
  *     or a {@link TypeVariable} whose bounds are interfaces
  * @return the created proxy instance
  */
 public static <E> E newEmptyProxy(Type... interfacesToBeProxied) {
   return Utilities.newEmptyProxy(null, interfacesToBeProxied);
 }
Exemplo n.º 8
0
 /**
  * Same as {@link #setUpMock(Class, Class)}, but accepting the (fully qualified) name of the real
  * class. This is useful when said class is not accessible from the test.
  *
  * @see <a
  *     href="http://code.google.com/p/jmockit/source/browse/trunk/main/test/integrationTests/textFile/TextFileUsingAnnotatedMockClassesTest.java#40">
  *     Example</a>
  */
 public static void setUpMock(String realClassName, Class<?> mockClass) {
   Class<?> realClass = Utilities.loadClass(realClassName);
   setUpMock(realClass, mockClass);
 }
Exemplo n.º 9
0
 /**
  * Same as {@link #stubOutClass(Class, boolean, String...)}, but accepting the (fully qualified)
  * name of the real class. This is useful when said class is not accessible from the test.
  */
 public static void stubOutClass(String realClassName, boolean inverse, String... filters) {
   Class<?> realClass = Utilities.loadClass(realClassName);
   new ClassStubbing(realClass, !inverse, filters).stubOut();
 }
Exemplo n.º 10
0
  /**
   * Sets the TabularData to the AaplicationTable
   *
   * @param data The TabularData to be set to the AaplicationTable
   */
  public void setAlarmTable(TabularData data) throws Exception {
    AgentException ae = null;

    for (Enumeration e = data.enumerate(); e.hasMoreElements(); ) {
      Object[] index = (Object[]) e.nextElement();
      CompositeData comp = data.getRow(index);

      if (table != null)
        entry =
            (AlarmEntry)
                Utilities.getEntryFromCompositeData(table, comp, indexNames, instrClassName);
      else if (vec != null)
        entry =
            (AlarmEntry) Utilities.getEntryFromCompositeData(vec, comp, indexNames, instrClassName);

      if (comp.getOperationType().equals(CompositeData.CREATED)) { // create new entry

        if (entry != null)
          throw new AgentException("Row already exist", CommonUtils.ROWCREATIONFAILED); // no i18n
        entry = new AlarmEntry();

        if (table != null) table.put(index, entry);
        else if (vec != null) vec.addElement(entry);
        for (Enumeration ce = comp.enumerate(); ce.hasMoreElements(); ) {
          String key = (String) ce.nextElement();
          try {
            Utilities.setField(entry, instrClassName, key, comp.getDataItem(key));
          } catch (AgentException aexp) {
            ae = aexp;
          }
        }
      } else if (comp.getOperationType().equals(CompositeData.DELETED)) {

        if (table != null) {
          for (Enumeration en = table.keys(); en.hasMoreElements(); ) {
            Object keyObject = en.nextElement();
            if (entry.equals(table.get(keyObject))) table.remove(keyObject);
          }
        } else if (vec != null)
          if (!vec.removeElement(entry))
            throw new AgentException("Invalid Index", CommonUtils.INVALIDINDEX); // no i18n
        data.deleteRow(index);
      } else if (comp.getOperationType().equals(CompositeData.MODIFIED)) {

        for (Enumeration ce = comp.enumerate(); ce.hasMoreElements(); ) {
          String key = (String) ce.nextElement();
          if (!comp.isModified(key)) continue;
          try {

            Utilities.setField(entry, instrClassName, key, comp.getDataItem(key));
          } catch (AgentException aexp) {
            ae = aexp;
          }
        }
      }

      comp.setOperationType(CompositeData.NOCHANGES);
    }

    if (ae != null) throw ae;
  }