Skip to content

Commit

Permalink
fix test for jdk8+
Browse files Browse the repository at this point in the history
  • Loading branch information
yasserzamani committed Jan 19, 2022
1 parent 88f04fa commit bb6c186
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.views.jsp.ui.AbstractUITag;
import org.fest.assertions.Assertions;

import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
Expand Down Expand Up @@ -213,34 +214,41 @@ public void verifyResource(String resource) throws Exception {
* Attempt to verify the contents of this.writer against the contents of the URL specified. verify() performs a
* trim on both ends
*
* @param url the HTML snippet that we want to validate against
* @param urls the HTML snippets that we want to validate against any of them
* @throws Exception if the validation failed
*/
public void verify(URL url) throws Exception {
if (url == null) {
fail("unable to verify a null URL");
} else if (this.writer == null) {
fail("AbstractJspWriter.writer not initialized. Unable to verify");
}
public void verify(URL... urls) throws Exception {
List<String> bufferStrings = new ArrayList<>();
for(URL url : urls) {
if (url == null) {
fail("unable to verify a null URL");
} else if (this.writer == null) {
fail("AbstractJspWriter.writer not initialized. Unable to verify");
}

StringBuilder buffer = new StringBuilder(128);
try (InputStream in = url.openStream()) {
byte[] buf = new byte[4096];
int nbytes;

while ((nbytes = in.read(buf)) > 0) {
buffer.append(new String(buf, 0, nbytes));
}
StringBuilder buffer = new StringBuilder(128);
try (InputStream in = url.openStream()) {
byte[] buf = new byte[4096];
int nbytes;

while ((nbytes = in.read(buf)) > 0) {
buffer.append(new String(buf, 0, nbytes));
}
}
bufferStrings.add(normalize(buffer.toString(), true));
}

/**
* compare the trimmed values of each buffer and make sure they're equivalent. however, let's make sure to
* normalize the strings first to account for line termination differences between platforms.
*/
String writerString = normalize(writer.toString(), true);
String bufferString = normalize(buffer.toString(), true);

assertEquals(bufferString, writerString);
if (bufferStrings.size() == 1) {
assertEquals(bufferStrings.get(0), writerString);
} else {
Assertions.assertThat(writerString).isIn(bufferStrings);
}
}

protected void setUp() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ public void testSimple_recursionTest() throws Exception {
tag.doStartTag();
tag.doEndTag();

verify(TextFieldTag.class.getResource("Textfield-5.txt"));
verify(TextFieldTag.class.getResource("Textfield-5.txt"),
TextFieldTag.class.getResource("Textfield-5jdk8.txt"));
}

public void testSimple_recursionTestNoValue() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<tr>
<td class="tdLabel"><label for="myname" class="label">mylabel:</label></td>
<td class="tdInput"><input type="text" name="myname" size="10" value="%{1+1}" id="myname" anotherAttr="%{1+1}" secondAttr="second_%{1+1}"/></td>
</tr>

0 comments on commit bb6c186

Please sign in to comment.