<commit_before>/*
 * Copyright 2015 Aroma Tech.
 *
 * 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 tech.aroma.banana.authentication.service.operations;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import tech.aroma.banana.authentication.service.data.TokenRepository;
import tech.aroma.banana.thrift.authentication.service.InvalidateApplicationTokenRequest;
import tech.aroma.banana.thrift.authentication.service.InvalidateApplicationTokenResponse;
import tech.aroma.banana.thrift.exceptions.InvalidArgumentException;
import tech.aroma.banana.thrift.exceptions.OperationFailedException;
import tech.sirwellington.alchemy.test.junit.runners.AlchemyTestRunner;
import tech.sirwellington.alchemy.test.junit.runners.GeneratePojo;
import tech.sirwellington.alchemy.test.junit.runners.Repeat;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static tech.sirwellington.alchemy.test.junit.ThrowableAssertion.assertThrows;

/**
 *
 * @author SirWellington
 */
@RunWith(AlchemyTestRunner.class)
public class InvalidateApplicationTokenOperationTest 
{
    @Mock
    private TokenRepository repository;
    
    @GeneratePojo
    private InvalidateApplicationTokenRequest request;
    private String tokenId;
    
    private InvalidateApplicationTokenOperation instance;

    @Before
    public void setUp()
    {
        instance = new InvalidateApplicationTokenOperation(repository);
        verifyZeroInteractions(repository);
        
        tokenId = request.token.tokenId;
    }
    
    @Test
    public void testConstructor()
    {
        assertThrows(() -> new InvalidateApplicationTokenOperation(null))
            .isInstanceOf(IllegalArgumentException.class);
    }

    @Repeat(200)
    @Test
    public void testProcess() throws Exception
    {
        InvalidateApplicationTokenResponse response = instance.process(request);
        assertThat(response, notNullValue());
        
        verify(repository).deleteToken(tokenId);
    }
    
    @Test
    public void testProcessEdgeCases() throws Exception
    {
        assertThrows(() -> instance.process(null))
            .isInstanceOf(InvalidArgumentException.class);
    }
    
    @Test
    public void testWhenRepositoryFails() throws Exception
    {
        doThrow(new RuntimeException())
            .when(repository)
            .deleteToken(tokenId);
        
        assertThrows(() -> instance.process(request))
            .isInstanceOf(OperationFailedException.class);
    }

}<commit_msg>Unit Test updates<commit_after>/*
 * Copyright 2015 Aroma Tech.
 *
 * 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 tech.aroma.banana.authentication.service.operations;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import tech.aroma.banana.authentication.service.data.TokenRepository;
import tech.aroma.banana.thrift.authentication.service.InvalidateApplicationTokenRequest;
import tech.aroma.banana.thrift.authentication.service.InvalidateApplicationTokenResponse;
import tech.aroma.banana.thrift.exceptions.InvalidArgumentException;
import tech.aroma.banana.thrift.exceptions.OperationFailedException;
import tech.sirwellington.alchemy.test.junit.runners.AlchemyTestRunner;
import tech.sirwellington.alchemy.test.junit.runners.GeneratePojo;
import tech.sirwellington.alchemy.test.junit.runners.Repeat;

import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static tech.sirwellington.alchemy.test.junit.ThrowableAssertion.assertThrows;

/**
 *
 * @author SirWellington
 */
@RunWith(AlchemyTestRunner.class)
public class InvalidateApplicationTokenOperationTest
{

    @Mock
    private TokenRepository repository;

    @GeneratePojo
    private InvalidateApplicationTokenRequest request;
    private String tokenId;

    private InvalidateApplicationTokenOperation instance;

    @Before
    public void setUp()
    {
        instance = new InvalidateApplicationTokenOperation(repository);
        verifyZeroInteractions(repository);

        tokenId = request.token.tokenId;
    }

    @Test
    public void testConstructor()
    {
        assertThrows(() -> new InvalidateApplicationTokenOperation(null))
            .isInstanceOf(IllegalArgumentException.class);
    }

    @Repeat(200)
    @Test
    public void testProcess() throws Exception
    {
        InvalidateApplicationTokenResponse response = instance.process(request);
        assertThat(response, notNullValue());

        verify(repository).deleteToken(tokenId);
    }

    @Test
    public void testProcessEdgeCases() throws Exception
    {
        assertThrows(() -> instance.process(null))
            .isInstanceOf(InvalidArgumentException.class);
    }

    @Test
    public void testWhenRepositoryFails() throws Exception
    {
        doThrow(new RuntimeException())
            .when(repository)
            .deleteToken(tokenId);

        assertThrows(() -> instance.process(request))
            .isInstanceOf(OperationFailedException.class);
    }

    @Test
    public void testWithMissingToken() throws Exception
    {
        request.token = null;

        assertThrows(() -> instance.process(request))
            .isInstanceOf(InvalidArgumentException.class);
    }

    @Test
    public void testWithMissingTokenId() throws Exception
    {
        request.token.tokenId = "";

        assertThrows(() -> instance.process(request))
            .isInstanceOf(InvalidArgumentException.class);
    }

}

{'fraction_non_alphanumeric': 0.08714056342139834, 'fraction_numerical': 0.003211210042329587, 'mean_word_length': 3.709278350515464, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '685960', 'n_tokens_mistral': 1861, 'n_tokens_neox': 1806, 'n_words': 423}