/*
 * Copyright (C) 2017 the original author or authors.
 *
 * This file is part of jBB Application Project.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  You may obtain a copy of the License at
 *        http://www.apache.org/licenses/LICENSE-2.0
 */

package org.jbb.security.impl.lock;


import org.jbb.security.impl.lock.dao.InvalidSignInAttemptRepository;
import org.jbb.security.impl.lock.dao.UserLockRepository;
import org.jbb.security.impl.lock.model.UserLockEntity;
import org.jbb.security.impl.lock.properties.UserLockProperties;
import org.jbb.security.impl.lock.service.UserLockServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class UserLockServiceImplTest {

    @Mock
    private InvalidSignInAttemptRepository invalidSignInAttemptRepository;

    @Mock
    private UserLockRepository userLockRepository;

    @Mock
    private UserLockProperties userLockProperties;

    @InjectMocks
    private UserLockServiceImpl userLockService;


    @Test
    public void whenServiceIsOfflineAndUserExceedInvalidSignInAttemptsThenUserIsNotLocked() {
        UserLockEntity user = createMemberWithExceedInvalidSignInAttempts();

    }

    private UserLockEntity createMemberWithExceedInvalidSignInAttempts() {
        return null;
    }

    private UserLockEntity createMemberWithEqualsInvalidSignInAttemptsToPropertiesValue() {
        return null;
    }

    private UserLockEntity createMemberWithNotExceedInvalidSignInAttempts() {
        return null;
    }
}

@@ -433,32 +433,100 @@
 LockRepository;%0A
+import org.jbb.security.impl.lock.model.InvalidSignInAttemptEntity;%0A
 import org.jbb.s
@@ -854,16 +854,180 @@
 unner;%0A%0A
+import static org.mockito.Matchers.any;%0Aimport static org.mockito.Mockito.never;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.when;%0A%0A
 @RunWith
@@ -1371,16 +1371,17 @@
 vice;%0A%0A%0A
+%0A
     @Tes
@@ -1476,24 +1476,25 @@
 ked() %7B%0A
+%0A
         
 UserLock
@@ -1489,411 +1489,437 @@
     
-UserLockEntity user = createMemberWithExceedInvalidSignInAttempts(
+//when%0A        when(userLockProperties.userSignInLockServiceEnable()).thenReturn(false
 );%0A
-%0A
     
-%7D%0A%0A
     
-private UserLockEntity createMemberWithExceedInvalidSignIn
+when(userLockProperties.userSignInMaximum
 Attempt
-s
 ()
- %7B%0A        return null;
+).thenReturn(2);%0A%0A        //then
 %0A    
-%7D%0A%0A
     
-private UserLockEntity createMemberWithEqualsInvalidSignInAttemptsToPropertiesValue() %7B%0A        return null;
+userLockService.lockUserIfQualify(1L);%0A%0A        //given
 %0A    
-%7D%0A%0A
     
-private UserLockEntity createMemberWithNotExceedInvalidSignInAttempts() %7B%0A        return null;
+verify(userLockRepository, never()).save(any(UserLockEntity.class));%0A        verify(invalidSignInAttemptRepository, never()).save(any(InvalidSignInAttemptEntity.class));%0A
 %0A    %7D%0A
+%0A%0A
 %7D%0A

Add first junit test to UL Service (service is turn off case)