Example #1
0
  public static ArtMethod hook(Constructor<?> originalMethod, Method replacementMethod) {
    Assertions.argumentNotNull(originalMethod, "originalMethod");
    Assertions.argumentNotNull(replacementMethod, "replacementMethod");
    if (replacementMethod.getReturnType() != Void.TYPE)
      throw new IllegalArgumentException("return types of replacementMethod has to be 'void'");

    return hook(ArtMethod.of(originalMethod), ArtMethod.of(replacementMethod));
  }
Example #2
0
  public static ArtMethod hook(Method originalMethod, Method replacementMethod) {
    Assertions.argumentNotNull(originalMethod, "originalMethod");
    Assertions.argumentNotNull(replacementMethod, "replacementMethod");
    if (originalMethod == replacementMethod || originalMethod.equals(replacementMethod))
      throw new IllegalArgumentException("originalMethod and replacementMethod can't be the same");
    if (!replacementMethod.getReturnType().isAssignableFrom(originalMethod.getReturnType()))
      throw new IllegalArgumentException(
          "return types of originalMethod and replacementMethod do not match");

    return hook(ArtMethod.of(originalMethod), ArtMethod.of(replacementMethod));
  }
Example #3
0
  public static void test(String string, String delim) {
    StringTokenizer tokenizer = new StringTokenizer(string, delim);

    int i = 0;
    while (tokenizer.hasMoreTokens()) {
      String nextToken = tokenizer.nextToken();
      int length = nextToken.length();
      if (i == 0) {
        Assertions.checkEquals("Togliere".length(), length);
      } else if (i == 1) {
        Assertions.checkEquals("sta".length(), length);
      } else if (i == 2) {
        Assertions.checkEquals("roba".length(), length);
      }
      i++;
    }
  }
Example #4
0
 public static void hook(Class clazz) {
   for (Method method : Assertions.argumentNotNull(clazz, "clazz").getDeclaredMethods()) {
     if (method.isAnnotationPresent(Hook.class)) {
       try {
         hook(method);
       } catch (RuntimeException e) {
         logw(e);
       }
     }
   }
 }
Example #5
0
  public static void test(int int0, int int1)
      throws SecurityException, NoSuchMethodException, IllegalArgumentException,
          IllegalAccessException, InvocationTargetException {

    TestCase88 instance0 = new TestCase88();
    Method method = TestCase88.class.getMethod("callbackMethodToIgnore", int.class, int.class);

    Object ret = method.invoke(instance0, int0, int1);
    int int2 = (Integer) ret;
    int int3 = 210;

    Assertions.checkEquals(int2, int3);
  }
Example #6
0
  /**
   * @param string0 .equals("135")
   * @param string1 .equals("20")
   * @param catchCount ==0
   */
  public static void test(String string0, String string1, int catchCount) {

    try {
      new BigInteger("Togliere sta roba");
    } catch (NumberFormatException ex) {
      catchCount++;
    }

    try {
      new BigInteger((String) null);
    } catch (NullPointerException ex) {
      catchCount++;
    }

    Assertions.checkEquals(2, catchCount);

    BigInteger bigInteger0 = new BigInteger(string0);
    BigInteger bigInteger1 = new BigInteger(string1);

    int int0 = bigInteger0.intValue();
    int int1 = bigInteger1.intValue();

    Assertions.checkEquals(135, int0);
    Assertions.checkEquals(20, int1);

    BigInteger[] bigIntegerArray0 = bigInteger0.divideAndRemainder(bigInteger1);

    BigInteger quotient = bigIntegerArray0[0];
    BigInteger remainder = bigIntegerArray0[1];

    int quotientInteger = quotient.intValue();
    int remainderInteger = remainder.intValue();

    Assertions.checkEquals(6, quotientInteger);
    Assertions.checkEquals(15, remainderInteger);

    BigInteger min = quotient.min(remainder);
    Assertions.checkEquals(min.intValue(), quotient.intValue());
  }
Example #7
0
 public static int findNalUnit(byte abyte0[], int i, int j, boolean aflag[])
 {
     boolean flag2 = true;
     int k = j - i;
     boolean flag;
     if (k >= 0)
     {
         flag = true;
     } else
     {
         flag = false;
     }
     Assertions.checkState(flag);
     if (k != 0)
     {
         if (aflag != null)
         {
             if (aflag[0])
             {
                 clearPrefixFlags(aflag);
                 return i - 3;
             }
             if (k > 1 && aflag[1] && abyte0[i] == 1)
             {
                 clearPrefixFlags(aflag);
                 return i - 2;
             }
             if (k > 2 && aflag[2] && abyte0[i] == 0 && abyte0[i + 1] == 1)
             {
                 clearPrefixFlags(aflag);
                 return i - 1;
             }
         }
         i += 2;
         while (i < j - 1) 
         {
             if ((abyte0[i] & 0xfe) == 0)
             {
                 if (abyte0[i - 2] == 0 && abyte0[i - 1] == 0 && abyte0[i] == 1)
                 {
                     if (aflag != null)
                     {
                         clearPrefixFlags(aflag);
                     }
                     return i - 2;
                 }
                 i -= 2;
             }
             i += 3;
         }
         if (aflag != null)
         {
             boolean flag1;
             if (k > 2)
             {
                 if (abyte0[j - 3] == 0 && abyte0[j - 2] == 0 && abyte0[j - 1] == 1)
                 {
                     flag1 = true;
                 } else
                 {
                     flag1 = false;
                 }
             } else
             if (k == 2)
             {
                 if (aflag[2] && abyte0[j - 2] == 0 && abyte0[j - 1] == 1)
                 {
                     flag1 = true;
                 } else
                 {
                     flag1 = false;
                 }
             } else
             if (aflag[1] && abyte0[j - 1] == 1)
             {
                 flag1 = true;
             } else
             {
                 flag1 = false;
             }
             aflag[0] = flag1;
             if (k > 1)
             {
                 if (abyte0[j - 2] == 0 && abyte0[j - 1] == 0)
                 {
                     flag1 = true;
                 } else
                 {
                     flag1 = false;
                 }
             } else
             if (aflag[2] && abyte0[j - 1] == 0)
             {
                 flag1 = true;
             } else
             {
                 flag1 = false;
             }
             aflag[1] = flag1;
             if (abyte0[j - 1] == 0)
             {
                 flag1 = flag2;
             } else
             {
                 flag1 = false;
             }
             aflag[2] = flag1;
             return j;
         }
     }
     return j;
 }
Example #8
0
  /**
   * Envia una peticion GET a la URL y devuelve toda la informacion disponible sobre el cuerpo,
   * cabeceras, conexion y tiempo
   *
   * @param strURL url donde se va a hacer la peticion
   * @param headers cabeceras que se quieran agregar a la peticion
   * @param connectionTimeout connectionTimeout que se quiere para la llamada
   * @param socketTimeout socketTimeout que se quiere para la llamada
   * @param testsToPerform los tests que se quieran realizar relacionados con la llamada y el
   *     resultado de la misma
   */
  public static void sendGet(
      String strURL,
      Object headers,
      Integer connectionTimeout,
      Integer socketTimeout,
      Object testsToPerform) {
    try {
      AbstractMap<String, String> localHeaders;

      Long localTimeout;
      Long localSocketTimeout;

      localHeaders = parser(headers);

      URL url = new URL(strURL);

      SemanticAnalysis.checkURL(url);

      if (connectionTimeout == null) {
        localTimeout = RequestAnswer.CONNECTION_TIMEOUT;
      } else {
        Long aux = new Long(connectionTimeout);
        if (aux < 0) {
          localTimeout = RequestAnswer.CONNECTION_TIMEOUT;
        } else {
          localTimeout = aux;
        }
      }

      if (socketTimeout == null) {
        localSocketTimeout = RequestAnswer.SOCKET_TIMEOUT;
      } else {
        Long aux = new Long(socketTimeout);
        if (aux < 0) {
          localSocketTimeout = RequestAnswer.SOCKET_TIMEOUT;
        } else {
          localSocketTimeout = aux;
        }
      }

      Unirest.setTimeouts(localTimeout, localSocketTimeout);

      long startTime = System.currentTimeMillis();

      HttpResponse<InputStream> jsonResponse =
          Unirest.get(url.toString()).headers(localHeaders).asBinary();

      long elapsedTime = System.currentTimeMillis() - startTime;

      setValues(url, jsonResponse, localHeaders, elapsedTime);

      BufferedReader in = new BufferedReader(new InputStreamReader(jsonResponse.getRawBody()));
      String inputLine;
      StringBuilder response = new StringBuilder();

      while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
      }
      in.close();
      if (response.length() != 0) {
        responseValues.setResponse(new StringBuilder(response));
      } else {
        responseValues.setResponse(new StringBuilder("No data"));
      }

      Assertions.executeTests(testsToPerform, jsonResponse, elapsedTime, response);
    } catch (UnirestException | SocketTimeoutException e) {
      e.printStackTrace();
      exceptionMessages.put("con", "This seems to be like an error connecting to ");
    } catch (MalformedURLException e) {
      exceptionMessages.put("url", "The URL is not well formed.");
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      exceptionMessages.put("url", "The URL is not well formed.");
    } catch (NullPointerException e) {
      e.printStackTrace();
    } catch (IOException e) {
      exceptionMessages.put("con", "This seems to be like an error connecting to ");
    } catch (JsonException e) {
      exceptionMessages.put(
          "parser",
          "There has been a problem parsing your custom values (params, request headers or tests).");
    }
  }
 @Test
 public void should_pass_actual() {
   Character b = 'b';
   AbstractCharacterAssert<?> assertions = Assertions.assertThat(b);
   assertSame(b, assertions.actual);
 }
 @Test
 public void should_create_Assert() {
   Character a = 'a';
   AbstractCharacterAssert<?> assertions = Assertions.assertThat(a);
   assertNotNull(assertions);
 }
 @Test(expected = IllegalArgumentException.class)
 public void testNotNullNull() throws Exception {
   Assertions.notNull(null, "object");
 }
 @Test
 public void testNotNull() throws Exception {
   Assertions.notNull(new Object(), "object");
 }