@Test public void roleHierarchyIsUsedWhenSet() throws Exception { RoleHierarchy rh = mock(RoleHierarchy.class); List rhAuthorities = AuthorityUtils.createAuthorityList("D"); when(rh.getReachableGrantedAuthorities(anyCollection())) .thenReturn(rhAuthorities); SidRetrievalStrategy strat = new SidRetrievalStrategyImpl(rh); List<Sid> sids = strat.getSids(authentication); assertThat(sids).hasSize(2); assertThat(sids.get(0)).isNotNull(); assertThat(sids.get(0) instanceof PrincipalSid).isTrue(); assertThat(((GrantedAuthoritySid) sids.get(1)).getGrantedAuthority()).isEqualTo("D"); } }
@Test // http@access-decision-manager-ref public void configureWhenAccessDecisionManagerSetThenVerifyUse() throws Exception { AccessDecisionManagerRefConfig.ACCESS_DECISION_MANAGER = mock(AccessDecisionManager.class); when(AccessDecisionManagerRefConfig.ACCESS_DECISION_MANAGER.supports(FilterInvocation.class)).thenReturn(true); when(AccessDecisionManagerRefConfig.ACCESS_DECISION_MANAGER.supports(any(ConfigAttribute.class))).thenReturn(true); this.spring.register(AccessDecisionManagerRefConfig.class).autowire(); this.mockMvc.perform(get("/")); verify(AccessDecisionManagerRefConfig.ACCESS_DECISION_MANAGER, times(1)).decide(any(Authentication.class), any(), anyCollection()); }
@Test public void getAllNullable() { // ask for 3 keys but only 2 are available in backed (third key is missing) List<String> keys = Arrays.asList("one", "two", "three"); Map<String, String> values = new HashMap<>(); values.put("one", "un"); values.put("two", "deux"); when(loader.loadAll(keys)).thenReturn(values); assertThat(cache.getAll(keys)) .hasSize(3) .containsEntry("one", "un") .containsEntry("two", "deux") .containsEntry("three", null); // ask for 4 keys. Only a single one was never loaded. The 3 others are kept from cache when(loader.loadAll(Arrays.asList("four"))).thenReturn(ImmutableMap.of("four", "quatre")); assertThat(cache.getAll(Arrays.asList("one", "two", "three", "four"))) .hasSize(4) .containsEntry("one", "un") .containsEntry("two", "deux") .containsEntry("three", null) .containsEntry("four", "quatre"); verify(loader, times(2)).loadAll(anyCollection()); } }
@Test public void putAllElements() { ArrayList<Element> elements = new ArrayList<>(); elements.add(createANode()); elements.add(createAWay()); elements.add(createARelation()); dao.putAll(elements); verify(nodeDao).putAll(anyCollection()); verify(wayDao).putAll(anyCollection()); verify(relationDao).putAll(anyCollection()); }
@Test public void putAllRelations() { ArrayList<Element> elements = new ArrayList<>(); elements.add(createARelation()); dao.putAll(elements); verify(relationDao).putAll(anyCollection()); }
@Test public void putAllNodes() { ArrayList<Element> elements = new ArrayList<>(); elements.add(createANode()); dao.putAll(elements); verify(nodeDao).putAll(anyCollection()); }
@Test public void putAllWays() { ArrayList<Element> elements = new ArrayList<>(); elements.add(createAWay()); dao.putAll(elements); verify(wayDao).putAll(anyCollection()); }
private void getRepositories() { context.getRepositories(callback); verify(callback).callback(anyCollection()); } }
@Test public void testEmpty() { reset(htmlValidator); presenter.init(SourceCodeType.HTML, null, new HashMap<>(), onChange); verify(htmlValidator, never()).validate(any()); reset(htmlValidator); presenter.init(SourceCodeType.HTML, "", new HashMap<>(), onChange); verify(htmlValidator, never()).validate(any()); reset(jsValidator); presenter.init(SourceCodeType.JAVASCRIPT, null, new HashMap<>(), onChange); verify(jsValidator, never()).validate(any(), anyCollection()); reset(jsValidator); presenter.init(SourceCodeType.JAVASCRIPT, "", new HashMap<>(), onChange); verify(jsValidator, never()).validate(any(), anyCollection()); }
@Test public void saveCollectionWithErrorTest() { doThrow(new RuntimeException("error")).when(store).save(anyCollection()); Collection<BasePreferencePortable<? extends BasePreference<?>>> preferences = new ArrayList<>(); preferences.add(new MyPreferencePortable()); preferenceBeanStoreImpl.save(preferences, successCommand, errorParameterizedCommand); verify(store).save(preferences); verify(errorParameterizedCommand).execute(any(Throwable.class)); }
@Test public void testEmpty() { reset(htmlValidator); presenter.init(SourceCodeType.HTML, null, new HashMap<>(), onChange); verify(htmlValidator, never()).validate(any()); reset(htmlValidator); presenter.init(SourceCodeType.HTML, "", new HashMap<>(), onChange); verify(htmlValidator, never()).validate(any()); reset(jsValidator); presenter.init(SourceCodeType.JAVASCRIPT, null, new HashMap<>(), onChange); verify(jsValidator, never()).validate(any(), anyCollection()); reset(jsValidator); presenter.init(SourceCodeType.JAVASCRIPT, "", new HashMap<>(), onChange); verify(jsValidator, never()).validate(any(), anyCollection()); }
@Test public void saveCollectionWithErrorTest() { doThrow(new RuntimeException("error")).when(store).save(anyCollection()); Collection<BasePreferencePortable<? extends BasePreference<?>>> preferences = new ArrayList<>(); preferences.add(new MyPreferencePortable()); preferenceBeanStoreImpl.save(preferences, successCommand, errorParameterizedCommand); verify(store).save(preferences); verify(errorParameterizedCommand).execute(any(Throwable.class)); }
@Test public void loadContentTest() { final PluginContent pluginContent = mock(PluginContent.class); when(pluginServices.getPluginContent(Matchers.<Path>any())).thenReturn(pluginContent); assertNull(editor.getOriginalHash()); editor.loadContent(); verify(pluginServices).getPluginContent(Matchers.<Path>any()); verify(baseEditorView).setFramework(anyCollection()); verify(baseEditorView).setupContent(eq(pluginContent), Matchers.<ParameterizedCommand<Media>>any()); verify(baseEditorView).hideBusyIndicator(); assertNotNull(editor.getOriginalHash()); }
@Test public void loadContentTest() { final PluginContent pluginContent = mock(PluginContent.class); when(pluginServices.getPluginContent(Matchers.<Path>any())).thenReturn(pluginContent); assertNull(editor.getOriginalHash()); editor.loadContent(); verify(pluginServices).getPluginContent(Matchers.<Path>any()); verify(baseEditorView).setFramework(anyCollection()); verify(baseEditorView).setupContent(eq(pluginContent), Matchers.<ParameterizedCommand<Media>>any()); verify(baseEditorView).hideBusyIndicator(); assertNotNull(editor.getOriginalHash()); }
@BeforeEach public void setUp() { initMocks(this); doCallRealMethod().when(mockResource).getMembershipResource(); doCallRealMethod().when(mockResource).getMemberRelation(); doCallRealMethod().when(mockResource).getMemberOfRelation(); doCallRealMethod().when(mockResource).getInsertedContentRelation(); doCallRealMethod().when(mockResource).stream(any(IRI.class)); doCallRealMethod().when(mockResource).stream(anyCollection()); doCallRealMethod().when(mockResource).getBinaryMetadata(); doCallRealMethod().when(mockResource).hasAcl(); doCallRealMethod().when(mockResource).getExtraLinkRelations(); when(mockResource.stream()).thenAnswer((x) -> empty()); }
@Test public void testReLoadRemembersBranches() throws Exception { context.changeBranch("your-repo", "release"); context.getRepositories(callback); assertEquals(2, result.size()); assertEquals("master", context.getCurrentBranch("my-repo")); assertEquals("release", context.getCurrentBranch("your-repo")); verify(callback, times(2)).callback(anyCollection()); }
@Test public void testReLoadPicksUpNewRepositories() throws Exception { repositories.add(makeRepository("my-new-repo", "master")); context.getRepositories(callback); assertEquals(3, result.size()); assertEquals("master", context.getCurrentBranch("my-repo")); assertEquals("master", context.getCurrentBranch("your-repo")); assertEquals("master", context.getCurrentBranch("my-new-repo")); verify(callback, times(2)).callback(anyCollection()); }
@Test public void testListen() throws Exception { conditions.add(new FieldCondition(new Field(mock(ObjectField.class), "Person", "String", "name", configuration), new Column(1, configuration), "==", new Values<>(10), configuration)); verify(allListener).onAllChanged(anyCollection()); }
@Test public void testListen() throws Exception { conditions.add( new FieldCondition( new Field( mock( ObjectField.class ), "Person", "String", "name", configuration ), new Column( 1, configuration ), "==", new Values<>( 10 ), configuration ) ); verify( allListener ).onAllChanged( anyCollection() ); }
@Test public void testUpdate() throws Exception { final Condition condition = new FieldCondition( new Field( mock( ObjectField.class ), "Person", "String", "name", configuration ), new Column( 1, configuration ), "==", new Values<>( 10 ), configuration ); conditions.add( condition ); reset( allListener ); condition.setValue( new Values<>( 20 ) ); verify( allListener ).onAllChanged( anyCollection() ); }