+ add setter for servlet minor version to MockServletContext
This commit is contained in:
Costin Leau 2009-11-09 11:51:30 +00:00
parent 7ec9f1506a
commit 9a111e504f
3 changed files with 41 additions and 8 deletions

View File

@ -97,6 +97,7 @@ public class MockServletContext implements ServletContext {
private String servletContextName = "MockServletContext"; private String servletContextName = "MockServletContext";
private int minorVersion = 5;
/** /**
* Create a new MockServletContext, using no base path and a * Create a new MockServletContext, using no base path and a
@ -181,7 +182,7 @@ public class MockServletContext implements ServletContext {
} }
public int getMinorVersion() { public int getMinorVersion() {
return 5; return this.minorVersion;
} }
public String getMimeType(String filePath) { public String getMimeType(String filePath) {
@ -340,6 +341,11 @@ public class MockServletContext implements ServletContext {
return this.servletContextName; return this.servletContextName;
} }
public void setMinorVersion(int minorVersion) {
if (minorVersion <3 || minorVersion > 5)
throw new IllegalArgumentException("Only Servlet minor versions between 3 and 5 are supported");
this.minorVersion = minorVersion;
}
/** /**
* Inner factory class used to just introduce a Java Activation Framework * Inner factory class used to just introduce a Java Activation Framework
@ -351,5 +357,4 @@ public class MockServletContext implements ServletContext {
return FileTypeMap.getDefaultFileTypeMap().getContentType(filePath); return FileTypeMap.getDefaultFileTypeMap().getContentType(filePath);
} }
} }
}
}

View File

@ -30,7 +30,8 @@ import org.junit.Test;
*/ */
public class MockServletContextTests { public class MockServletContextTests {
@Ignore // fails to work under ant after move from .testsuite -> .test @Ignore
// fails to work under ant after move from .testsuite -> .test
@Test @Test
public void testListFiles() { public void testListFiles() {
MockServletContext sc = new MockServletContext("org/springframework/mock"); MockServletContext sc = new MockServletContext("org/springframework/mock");
@ -39,7 +40,8 @@ public class MockServletContextTests {
assertTrue(paths.contains("/web/MockServletContextTests.class")); assertTrue(paths.contains("/web/MockServletContextTests.class"));
} }
@Ignore // fails to work under ant after move from .testsuite -> .test @Ignore
// fails to work under ant after move from .testsuite -> .test
@Test @Test
public void testListSubdirectories() { public void testListSubdirectories() {
MockServletContext sc = new MockServletContext("org/springframework/mock"); MockServletContext sc = new MockServletContext("org/springframework/mock");
@ -79,4 +81,24 @@ public class MockServletContextTests {
assertEquals("image/gif", sc.getMimeType("test.gif")); assertEquals("image/gif", sc.getMimeType("test.gif"));
} }
@Test
public void testMinorVersion() {
MockServletContext sc = new MockServletContext();
assertEquals(5, sc.getMinorVersion());
sc.setMinorVersion(4);
assertEquals(4, sc.getMinorVersion());
}
@Test
public void testIllegalMinorVersion() {
MockServletContext sc = new MockServletContext();
assertEquals(5, sc.getMinorVersion());
try {
sc.setMinorVersion(2);
fail("expected expection for illegal argument");
}
catch (IllegalArgumentException iae) {
// expected
}
}
} }

View File

@ -97,6 +97,8 @@ public class MockServletContext implements ServletContext {
private String servletContextName = "MockServletContext"; private String servletContextName = "MockServletContext";
private int minorVersion = 5;
/** /**
* Create a new MockServletContext, using no base path and a * Create a new MockServletContext, using no base path and a
@ -181,7 +183,7 @@ public class MockServletContext implements ServletContext {
} }
public int getMinorVersion() { public int getMinorVersion() {
return 5; return minorVersion;
} }
public String getMimeType(String filePath) { public String getMimeType(String filePath) {
@ -340,6 +342,11 @@ public class MockServletContext implements ServletContext {
return this.servletContextName; return this.servletContextName;
} }
public void setMinorVersion(int minorVersion) {
if (minorVersion <3 || minorVersion > 5)
throw new IllegalArgumentException("Only Servlet minor versions between 3 and 5 are supported");
this.minorVersion = minorVersion;
}
/** /**
* Inner factory class used to just introduce a Java Activation Framework * Inner factory class used to just introduce a Java Activation Framework
@ -351,5 +358,4 @@ public class MockServletContext implements ServletContext {
return FileTypeMap.getDefaultFileTypeMap().getContentType(filePath); return FileTypeMap.getDefaultFileTypeMap().getContentType(filePath);
} }
} }
}
}