<commit_before>/**
 * Copyright (C) 2011  JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jtalks.poulpe.web.controller.section.dialogs;

import org.jtalks.poulpe.model.entity.PoulpeBranch;
import org.jtalks.poulpe.service.ForumStructureService;
import org.jtalks.poulpe.service.exceptions.JcommuneRespondedWithErrorException;
import org.jtalks.poulpe.service.exceptions.JcommuneUrlNotConfiguredException;
import org.jtalks.poulpe.service.exceptions.NoConnectionToJcommuneException;
import org.jtalks.poulpe.web.controller.section.ForumStructureItem;
import org.jtalks.poulpe.web.controller.section.ForumStructureVm;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import static org.mockito.Mockito.*;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

/**
 * @author <NAME>
 */
public class DeleteBranchDialogVmTest {
    private  DeleteBranchDialogVm sut;
    private  ForumStructureService forumStructureService;
    private  ForumStructureVm forumStructureVm;

    @BeforeMethod
    public void beforeMethod(){
        forumStructureService = mock(ForumStructureService.class);
        forumStructureVm = mock(ForumStructureVm.class);
        sut = spy(new DeleteBranchDialogVm(forumStructureVm,forumStructureService));
    }

    @Test
    public void testIsShowDialog() throws Exception {
        sut.showDialog();
        assertTrue(sut.isShowDialog());
        assertFalse(sut.isShowDialog());
    }

    @Test
    public void testDeleteBranch(){
        sut.deleteBranch();
    }

    @Test
    public void testConfirmDeleteBranchWithContentNoConnection()
        throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        testConfirmDeleteBranchWithContent("branches.error.jcommune_no_connection", new NoConnectionToJcommuneException());
    }

    @Test
    public void testConfirmDeleteBranchWithContentJcommuneResponded()
            throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        testConfirmDeleteBranchWithContent("branches.error.jcommune_no_response", new JcommuneRespondedWithErrorException());
    }

    @Test
    public void testConfirmDeleteBranchWithContentJcommuneUrl()
            throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        testConfirmDeleteBranchWithContent("branches.error.jcommune_no_url", new JcommuneUrlNotConfiguredException());
    }

    @Test
    public void testConfirmDeleteBranchWithContentNoException()
            throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        testConfirmDeleteBranchWithContent(null,null);
    }

    private void testConfirmDeleteBranchWithContent(String message, Exception exception)
            throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        PoulpeBranch branch = new PoulpeBranch();
        ForumStructureItem forumStructureItem = new ForumStructureItem(branch);
        when(forumStructureVm.getSelectedItemInTree()).thenReturn(forumStructureItem);
        if(exception!=null){
            doNothing().when(sut).showError(message);
            doThrow(exception).when(forumStructureService).removeBranch(branch);
        }else{
            doNothing().when(forumStructureService).removeBranch(branch);
            doNothing().when(forumStructureVm).removeBranchFromTree(branch);
        }
        sut.confirmDeleteBranchWithContent();
    }

}<commit_msg>added to test: if a branch is deleted it should be deleted from model<commit_after>/**
 * Copyright (C) 2011  JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jtalks.poulpe.web.controller.section.dialogs;

import org.jtalks.poulpe.model.entity.PoulpeBranch;
import org.jtalks.poulpe.service.ForumStructureService;
import org.jtalks.poulpe.service.exceptions.JcommuneRespondedWithErrorException;
import org.jtalks.poulpe.service.exceptions.JcommuneUrlNotConfiguredException;
import org.jtalks.poulpe.service.exceptions.NoConnectionToJcommuneException;
import org.jtalks.poulpe.web.controller.section.ForumStructureItem;
import org.jtalks.poulpe.web.controller.section.ForumStructureVm;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import static org.mockito.Mockito.*;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;

/**
 * @author <NAME>
 */
public class DeleteBranchDialogVmTest {
    private  DeleteBranchDialogVm sut;
    private  ForumStructureService forumStructureService;
    private  ForumStructureVm forumStructureVm;

    @BeforeMethod
    public void beforeMethod(){
        forumStructureService = mock(ForumStructureService.class);
        forumStructureVm = mock(ForumStructureVm.class);
        sut = spy(new DeleteBranchDialogVm(forumStructureVm,forumStructureService));
    }

    @Test
    public void testIsShowDialog() throws Exception {
        sut.showDialog();
        assertTrue(sut.isShowDialog());
        assertFalse(sut.isShowDialog());
    }

    @Test
    public void testDeleteBranch() throws Exception {
        sut.deleteBranch();
    }

    @Test
    public void testConfirmDeleteBranchWithContentNoConnection()
        throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        testConfirmDeleteBranchWithContent("branches.error.jcommune_no_connection", new NoConnectionToJcommuneException());
    }

    @Test
    public void testConfirmDeleteBranchWithContentJcommuneResponded()
            throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        testConfirmDeleteBranchWithContent("branches.error.jcommune_no_response", new JcommuneRespondedWithErrorException());
    }

    @Test
    public void testConfirmDeleteBranchWithContentJcommuneUrl()
            throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        testConfirmDeleteBranchWithContent("branches.error.jcommune_no_url", new JcommuneUrlNotConfiguredException());
    }

    @Test
    public void testConfirmDeleteBranchWithContentNoException()
            throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        testConfirmDeleteBranchWithContent(null,null);
        verify(forumStructureService).removeBranch(any(PoulpeBranch.class));
        verify(forumStructureVm).removeBranchFromTree(any(PoulpeBranch.class));
    }

    private void testConfirmDeleteBranchWithContent(String message, Exception exception)
            throws NoConnectionToJcommuneException,JcommuneRespondedWithErrorException,JcommuneUrlNotConfiguredException{
        PoulpeBranch branch = new PoulpeBranch();
        ForumStructureItem forumStructureItem = new ForumStructureItem(branch);
        when(forumStructureVm.getSelectedItemInTree()).thenReturn(forumStructureItem);
        if(exception!=null){
            doNothing().when(sut).showError(message);
            doThrow(exception).when(forumStructureService).removeBranch(branch);
        }else{
            doNothing().when(forumStructureService).removeBranch(branch);
            doNothing().when(forumStructureVm).removeBranchFromTree(branch);
        }
        sut.confirmDeleteBranchWithContent();
    }

}
{'fraction_non_alphanumeric': 0.07261944724180373, 'fraction_numerical': 0.0038044086382454964, 'mean_word_length': 4.7479099678456596, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2022409', 'n_tokens_mistral': 2427, 'n_tokens_neox': 2403, 'n_words': 513}