/** * Asserts that the array of characters contains a given char * * @param expected expected character to be found * @param array the array */ protected void assertContains(char expected, char[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuilder message = new StringBuilder(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the array of ints contains a given int * * @param expected expected int * @param array the array */ protected void assertContains(int expected, int[] array) { for (int anInt : array) { if (anInt == expected) { return; } } StringBuilder message = new StringBuilder(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
protected String shouldFailWithCause(Class clazz, Closure code) { Throwable th = null; try { code.call(); } catch (GroovyRuntimeException gre) { th = gre; while (th.getCause()!=null && th.getCause()!=gre){ // if wrapped, find the root cause th=th.getCause(); if (th!=gre && (th instanceof GroovyRuntimeException)) { gre = (GroovyRuntimeException) th; } } } catch (Throwable e) { th = e; } if (th==null) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName()); } else if (! clazz.isInstance(th)) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th); } return th.getMessage(); }
protected String shouldFailWithCause(Class clazz, Closure code) { Throwable th = null; try { code.call(); } catch (GroovyRuntimeException gre) { th = gre; while (th.getCause()!=null && th.getCause()!=gre){ // if wrapped, find the root cause th=th.getCause(); if (th!=gre && (th instanceof GroovyRuntimeException)) { gre = (GroovyRuntimeException) th; } } } catch (Throwable e) { th = e; } if (th==null) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName()); } else if (! clazz.isInstance(th)) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th); } return th.getMessage(); }
protected String shouldFailWithCause(Class clazz, Closure code) { Throwable th = null; try { code.call(); } catch (GroovyRuntimeException gre) { th = gre; while (th.getCause()!=null && th.getCause()!=gre){ // if wrapped, find the root cause th=th.getCause(); if (th!=gre && (th instanceof GroovyRuntimeException)) { gre = (GroovyRuntimeException) th; } } } catch (Throwable e) { th = e; } if (th==null) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName()); } else if (! clazz.isInstance(th)) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th); } return th.getMessage(); }
/** * Asserts that the array of characters contains a given char * * @param expected expected character to be found * @param array the array */ protected void assertContains(char expected, char[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuilder message = new StringBuilder(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the given code closure fails when it is evaluated * and that a particular exception is thrown. * * @param clazz the class of the expected exception * @param code the closure that should fail * @return the message of the expected Throwable */ protected String shouldFail(Class clazz, Closure code) { Throwable th = null; try { code.call(); } catch (GroovyRuntimeException gre) { th = ScriptBytecodeAdapter.unwrap(gre); } catch (Throwable e) { th = e; } if (th==null) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName()); } else if (! clazz.isInstance(th)) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th); } return th.getMessage(); }
/** * Asserts that the array of ints contains a given int * * @param expected expected int * @param array the array */ protected void assertContains(int expected, int[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuffer message = new StringBuffer(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the array of ints contains a given int * * @param expected expected int * @param array the array */ protected void assertContains(int expected, int[] array) { for (int anInt : array) { if (anInt == expected) { return; } } StringBuffer message = new StringBuffer(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the array of ints contains a given int * * @param expected expected int * @param array the array */ protected void assertContains(int expected, int[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuffer message = new StringBuffer(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the given code closure fails when it is evaluated * and that a particular exception is thrown. * * @param clazz the class of the expected exception * @param code the closure that should fail * @return the message of the expected Throwable */ protected String shouldFail(Class clazz, Closure code) { Throwable th = null; try { code.call(); } catch (GroovyRuntimeException gre) { th = ScriptBytecodeAdapter.unwrap(gre); } catch (Throwable e) { th = e; } if (th==null) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName()); } else if (! clazz.isInstance(th)) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th); } return th.getMessage(); }
/** * Asserts that the array of characters contains a given char * * @param expected expected character to be found * @param array the array */ protected void assertContains(char expected, char[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuffer message = new StringBuffer(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the array of characters contains a given char * * @param expected expected character to be found * @param array the array */ protected void assertContains(char expected, char[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuffer message = new StringBuffer(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the array of ints contains a given int * * @param expected expected int * @param array the array */ protected void assertContains(int expected, int[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuffer message = new StringBuffer(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the array of characters contains a given char * * @param expected expected character to be found * @param array the array */ protected void assertContains(char expected, char[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuffer message = new StringBuffer(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the array of characters contains a given char * * @param expected expected character to be found * @param array the array */ protected void assertContains(char expected, char[] array) { for (int i = 0; i < array.length; ++i) { if (array[i] == expected) { return; } } StringBuffer message = new StringBuffer(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the array of ints contains a given int * * @param expected expected int * @param array the array */ protected void assertContains(int expected, int[] array) { for (int anInt : array) { if (anInt == expected) { return; } } StringBuilder message = new StringBuilder(); message.append(expected).append(" not in {"); for (int i = 0; i < array.length; ++i) { message.append("'").append(array[i]).append("'"); if (i < (array.length - 1)) { message.append(", "); } } message.append(" }"); fail(message.toString()); }
/** * Asserts that the given code closure fails when it is evaluated * and that a particular exception is thrown. * * @param clazz the class of the expected exception * @param code the closure that should fail * @return the message of the expected Throwable */ protected String shouldFail(Class clazz, Closure code) { Throwable th = null; try { code.call(); } catch (GroovyRuntimeException gre) { th = unwrap(gre); } catch (Throwable e) { th = e; } if (th==null) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName()); } else if (! clazz.isInstance(th)) { fail("Closure " + code + " should have failed with an exception of type " + clazz.getName() + ", instead got Exception " + th); } return th.getMessage(); }
log.info("Running " + testMethod.getName() + " as not yet implemented"); testMethod.invoke(caller, (Object[]) new Class[]{}); fail(testMethod.getName() + " is marked as not yet implemented but passes unexpectedly");
log.info("Running " + testMethod.getName() + " as not yet implemented"); testMethod.invoke(caller, (Object[]) new Class[] {}); fail(testMethod.getName() + " is marked as not yet implemented but passes unexpectedly");