Commit 275ffa39 authored by Nanfeng Liu's avatar Nanfeng Liu
Browse files

fix bugs of short querys

parent f5ca1129
Pipeline #63724 canceled with stages
in 3 minutes and 48 seconds
......@@ -39,18 +39,23 @@ public class WebServer {
public static Page execute(String query, String type) {
if (query == null) {
return new IndexPage();
} else {
String result = new QueryProcessor().process(query);
if(type == null){
return new HTMLResultPage(query, result);
}else if (type.equals("markdown")){
return new MarkDownPage(query, result);
}else{
return new PdfPage(query, result);
}
if (query.length() <3){
query += " ";
/* java.lang.IllegalArgumentException: Prefix string
"" too short: length must be at least 3 */
}
if (query == null) {
return new IndexPage();
} else {
String result = new QueryProcessor().process(query);
if(type == null){
return new HTMLResultPage(query, result);
}else if (type.equals("markdown")){
return new MarkDownPage(query, result);
}else{
return new PdfPage(query, result);
}
}
}
......
......@@ -5,6 +5,10 @@ import java.io.IOException;
import java.io.PrintWriter;
public class IndexPage implements Page {
@Override
public String getQuery(){
return null;
}
public void writeTo(HttpServletResponse resp) throws IOException {
resp.setContentType("text/html");
......
......@@ -13,4 +13,9 @@ public abstract class NoneIndexPage implements Page{
public String getAnswer(){
return answer;
}
@Override
public String getQuery(){
return query;
}
}
......@@ -6,4 +6,5 @@ import java.io.IOException;
public interface Page {
void writeTo(HttpServletResponse resp) throws IOException, InterruptedException;
String getAnswer();
String getQuery();
}
......@@ -47,13 +47,7 @@ public class doGetTest {
Page p = execute("shakespeare", "markdown");
assertTrue(p instanceof MarkDownPage);
}
@Test
public void emptyQueryReturnsHTML(){
Page p = execute(null, null);
assertTrue(p instanceof IndexPage);
}
//test that there is a markdown file created
@Test
public void markdownFileCreated() throws Exception {
......@@ -77,4 +71,12 @@ public class doGetTest {
assertTrue(pdf.isFile());
}
@Test
public void queryIsToShort() {
Page p = execute("s", null);
assertTrue(p.getQuery().equals("s "));
p = execute("", null);
assertTrue(p.getQuery().equals(" "));
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment