Skip to content

Commit

Permalink
fix: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Anisimov committed Nov 26, 2020
1 parent ae6a159 commit c838502
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ public void init(ServletConfig servletConfig) throws ServletException {
CurrentInstance.clearAll();

try {
/*
* There are plenty of reasons why the check should be done. The
* main reason is: init method is public which means that everyone
* may call this method at any time (including an app developer).
* But it's not supposed to be called any times any time.
*
* This code protects weak API from being called several times so
* that config is reset after the very first initialization.
*
* Normally "init" method is called only once by the servlet
* container. But in a specific OSGi case {@code
* ServletCointextListener} may be called after the servlet
* initialized. To be able to initialize the VaadinServlet properly
* its "init" method is called from the {@code
* ServletCointextListener} with the same ServletConfig instance.
*/
if (getServletConfig() == null) {
super.init(servletConfig);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public void init() {
try {
MockVaadinServlet servlet = (MockVaadinServlet) getServlet();
servlet.service = this;
getServlet().init(new MockServletConfig());
if (getServlet().getServletConfig() == null) {
getServlet().init(new MockServletConfig());
}
super.init();
} catch (ServiceException | ServletException e) {
throw new RuntimeException(e);
Expand Down

0 comments on commit c838502

Please sign in to comment.