Skip to content

Commit

Permalink
fix: report Lookup instance absence with ISE and meaningful message (#…
Browse files Browse the repository at this point in the history
…11240) (#11272)

fixes #11219

Co-authored-by: Denis <denis@vaadin.com>
  • Loading branch information
vaadin-bot and Denis committed Jun 17, 2021
1 parent c21b8bd commit c0ec3c5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public interface ApplicationConfiguration extends AbstractConfiguration {
static ApplicationConfiguration get(VaadinContext context) {
return context.getAttribute(ApplicationConfiguration.class, () -> {
Lookup lookup = context.getAttribute(Lookup.class);
if (lookup == null) {
throw new IllegalStateException("The application "
+ Lookup.class.getSimpleName()
+ " instance is not found in the " + VaadinContext.class
+ " instance. It means that "
+ "the container has not executed "
+ Lookup.class.getSimpleName()
+ " initialization code: so either the container is not Servlet 3.0 compatible"
+ " or project configuration is broken.");
}
ApplicationConfigurationFactory factory = lookup
.lookup(ApplicationConfigurationFactory.class);
return factory.create(context);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2000-2021 Vaadin Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.vaadin.flow.server.startup;

import java.util.function.Supplier;

import org.junit.Test;
import org.mockito.Mockito;

import com.vaadin.flow.di.Lookup;
import com.vaadin.flow.server.VaadinContext;

public class ApplicationConfigurationTest {

@Test(expected = IllegalStateException.class)
public void get_contextHasNoLookup_iseIsThrown() {
VaadinContext context = Mockito.spy(VaadinContext.class);
Mockito.when(context.getAttribute(Lookup.class)).thenReturn(null);
Mockito.doAnswer(
invocation -> invocation.getArgument(1, Supplier.class).get())
.when(context).getAttribute(Mockito.any(), Mockito.any());
ApplicationConfiguration.get(context);
}

}

0 comments on commit c0ec3c5

Please sign in to comment.