public static Matcher<String> containsIgnoringWhitespace(final String expected){ return new TypeSafeMatcher<String>(){ @Override public void describeTo(Description description) { description.appendText(expected); //don't bother to add the fact that it contains ignoring case } @Override protected boolean matchesSafely(String actual) { String strippedActual = stripSpace(actual); String strippedExpected = stripSpace(expected); return containsString(strippedExpected).matches(strippedActual); } private String stripSpace(String string) { return new IsEqualIgnoringWhiteSpace("").stripSpace(string); } }; }
@Test public void runCodeSimple() throws Exception { ResultActions actions = this.mockMvc.perform(post("/jhawtcode/dynacode").param("code", "jhc.println(true);").param("replacementCP", fullClassPath)); //actions.andDo(print()); actions.andExpect(status().isOk()); //not the best content test, but works for now until gzip deflate actions.andExpect(content().string(new IsNot(new IsNull()))); actions.andExpect(content().string(new IsNot(new IsEmptyString()))); actions.andExpect(content().string(new IsEqualIgnoringWhiteSpace("true"))); }
@Test public void runCodeSimpleWithImport() throws Exception { ResultActions actions = this.mockMvc.perform(post("/jhawtcode/dynacode").param("code", "jhc.println(Math.pow(3,3));").param("replacementCP", fullClassPath).param("imports", "import java.lang.Math;")); //actions.andDo(print()); actions.andExpect(status().isOk()); //not the best content test, but works for now until gzip deflate actions.andExpect(content().string(new IsNot(new IsNull()))); actions.andExpect(content().string(new IsNot(new IsEmptyString()))); actions.andExpect(content().string(new IsEqualIgnoringWhiteSpace("27.0"))); }
@Test public void runCodeSimpleWithImportAndMethod() throws Exception { ResultActions actions = this.mockMvc.perform(post("/jhawtcode/dynacode").param("code", "jhc.println(Math.pow(3,addem(2,1)));").param("replacementCP", fullClassPath).param("imports", "import java.lang.Math;").param("methods", "public int addem(int a, int b) { return a+b; }")); //actions.andDo(print()); actions.andExpect(status().isOk()); //not the best content test, but works for now until gzip deflate actions.andExpect(content().string(new IsNot(new IsNull()))); actions.andExpect(content().string(new IsNot(new IsEmptyString()))); actions.andExpect(content().string(new IsEqualIgnoringWhiteSpace("27.0"))); }
@Test public void runCodeSimpleWithImportAndMethodAndGlobal() throws Exception { ResultActions actions = this.mockMvc.perform(post("/jhawtcode/dynacode").param("code", "jhc.println(Math.pow(3,addem(1,1)));").param("replacementCP", fullClassPath).param("imports", "import java.lang.Math;").param("methods", "public int addem(int a, int b) { return a+b+MYVAR; }").param("globals", "private int MYVAR=1;")); //actions.andDo(print()); actions.andExpect(status().isOk()); //not the best content test, but works for now until gzip deflate actions.andExpect(content().string(new IsNot(new IsNull()))); actions.andExpect(content().string(new IsNot(new IsEmptyString()))); actions.andExpect(content().string(new IsEqualIgnoringWhiteSpace("27.0"))); }
private String stripSpace(String string) { return new IsEqualIgnoringWhiteSpace("").stripSpace(string); }
@Test public void testGetPathExpression() { final String result = program.getPathExpression(backend); Assert.assertThat(result, IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace(expr)); }
@Test public void testGetPathExpression() { Assert.assertThat(test.getPathExpression(backend), IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace(expr)); }
@Test public void testGetPathExpression() { Assert.assertThat(selector.getPathExpression(backend), IsEqualIgnoringWhiteSpace.equalToIgnoringWhiteSpace(expr)); }