-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport ViewScope implementation (#489)
* Backport ViewScope implementation * Backport ViewScope tests * fix pmd * backport coverage limits
- Loading branch information
1 parent
e9b2a84
commit 3b3fd23
Showing
7 changed files
with
497 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...autoconfigure/src/test/java/org/joinfaces/integration/DestructionCallbackWrapperTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2016-2018 the original author or authors. | ||
* | ||
* 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 org.joinfaces.integration; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class DestructionCallbackWrapperTest { | ||
|
||
private ViewScope.DestructionCallbackWrapper destructionCallbackWrapper; | ||
private Runnable callback; | ||
|
||
@Before | ||
public void setUp() { | ||
this.callback = Mockito.mock(Runnable.class); | ||
this.destructionCallbackWrapper = new ViewScope.DestructionCallbackWrapper("bean", this.callback); | ||
} | ||
|
||
@Test | ||
public void onSessionDestroy() { | ||
assertThat(this.destructionCallbackWrapper.isCallbackCalled()).isFalse(); | ||
this.destructionCallbackWrapper.onSessionDestroy(); | ||
Mockito.verify(this.callback).run(); | ||
assertThat(this.destructionCallbackWrapper.isCallbackCalled()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void testRunCalledOnlyOnce() { | ||
this.destructionCallbackWrapper.onViewDestroy(); | ||
this.destructionCallbackWrapper.onSessionDestroy(); | ||
Mockito.verify(this.callback).run(); | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...-autoconfigure/src/test/java/org/joinfaces/integration/PreDestroyViewMapListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright 2016-2018 the original author or authors. | ||
* | ||
* 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 org.joinfaces.integration; | ||
|
||
import javax.faces.event.PreDestroyViewMapEvent; | ||
|
||
import org.joinfaces.test.mock.JsfIT; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.mockito.BDDMockito.mock; | ||
import static org.mockito.BDDMockito.verify; | ||
import static org.mockito.BDDMockito.when; | ||
|
||
public class PreDestroyViewMapListenerTest extends JsfIT { | ||
|
||
private ViewScope.PreDestroyViewMapListener preDestroyViewMapListener; | ||
|
||
@Before | ||
public void setUp() { | ||
ViewScope viewScope = new ViewScope(); | ||
|
||
this.preDestroyViewMapListener = viewScope.getPreDestroyViewMapListener(); | ||
} | ||
|
||
@Test | ||
public void testProcessEvent() { | ||
PreDestroyViewMapEvent event = mock(PreDestroyViewMapEvent.class); | ||
|
||
when(event.getSource()).thenReturn(getJsfMock().getMockViewRoot()); | ||
when(getJsfMock().getMockViewRoot().getViewMap(false)) | ||
.thenReturn(getJsfMock().getMockViewMap()); | ||
|
||
Runnable runnable = mock(Runnable.class); | ||
ViewScope.DestructionCallbackWrapper destructionCallbackWrapper = new ViewScope.DestructionCallbackWrapper( | ||
"foo", runnable | ||
); | ||
|
||
getJsfMock().getMockViewMap() | ||
.put(ViewScope.DESTRUCTION_CALLBACK_NAME_PREFIX + "foo", destructionCallbackWrapper); | ||
|
||
this.preDestroyViewMapListener.processEvent(event); | ||
|
||
verify(runnable).run(); | ||
} | ||
} |
Oops, something went wrong.