Skip to content

Commit 25c0ef2

Browse files
cse.saiful2119@gmail.commm-saiful6854
authored andcommitted
FINERACT-2045: add unit test to verify gl account deletion when gl account has not dependencies
1 parent 768416a commit 25c0ef2

1 file changed

Lines changed: 86 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.fineract.accounting.glaccount.service;
20+
21+
import static org.junit.jupiter.api.Assertions.assertEquals;
22+
import static org.junit.jupiter.api.Assertions.assertNotNull;
23+
import static org.mockito.ArgumentMatchers.any;
24+
import static org.mockito.Mockito.times;
25+
import static org.mockito.Mockito.verify;
26+
import static org.mockito.Mockito.when;
27+
28+
import java.util.Optional;
29+
import org.apache.fineract.accounting.glaccount.domain.GLAccount;
30+
import org.apache.fineract.accounting.glaccount.domain.GLAccountRepository;
31+
import org.apache.fineract.accounting.journalentry.domain.JournalEntryRepository;
32+
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMappingRepository;
33+
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
34+
import org.junit.jupiter.api.BeforeEach;
35+
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.extension.ExtendWith;
37+
import org.mockito.InjectMocks;
38+
import org.mockito.Mock;
39+
import org.mockito.junit.jupiter.MockitoExtension;
40+
import org.springframework.data.jpa.domain.Specification;
41+
42+
@ExtendWith(MockitoExtension.class)
43+
class GLAccountWritePlatformServiceJpaRepositoryImplTest {
44+
45+
@Mock
46+
private GLAccountRepository glAccountRepository;
47+
48+
@Mock
49+
private JournalEntryRepository glJournalEntryRepository;
50+
51+
@Mock
52+
private ProductToGLAccountMappingRepository productToGLAccountMappingRepository;
53+
54+
@InjectMocks
55+
private GLAccountWritePlatformServiceJpaRepositoryImpl glAccountWritePlatformService;
56+
57+
private GLAccount glAccount;
58+
private static final Long GL_ACCOUNT_ID = 123L;
59+
60+
@BeforeEach
61+
void setUp() {
62+
glAccount = new GLAccount();
63+
glAccount.setId(GL_ACCOUNT_ID);
64+
glAccount.setName("Test Account");
65+
glAccount.setGlCode("TEST001");
66+
}
67+
68+
/**
69+
* Verify that a GL account can be deleted when it has no dependencies.
70+
*/
71+
@Test
72+
void testDeleteGLAccountSuccessWithNoDependencies() {
73+
// Given: A GL account with no children, no journal entries, and no product mappings
74+
when(glAccountRepository.findById(GL_ACCOUNT_ID)).thenReturn(Optional.of(glAccount));
75+
when(glJournalEntryRepository.exists(any(Specification.class))).thenReturn(false);
76+
when(productToGLAccountMappingRepository.exists(any(Specification.class))).thenReturn(false);
77+
78+
// When: Attempting to delete the GL account
79+
CommandProcessingResult result = glAccountWritePlatformService.deleteGLAccount(GL_ACCOUNT_ID);
80+
81+
// Then: The deletion should succeed
82+
assertNotNull(result);
83+
assertEquals(GL_ACCOUNT_ID, result.getResourceId());
84+
verify(glAccountRepository, times(1)).delete(glAccount);
85+
}
86+
}

0 commit comments

Comments
 (0)