<commit_before>package com.exp.tracker.services.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl;

import com.exp.tracker.data.entities.ExpenseEntity;
import com.exp.tracker.data.model.ExpenseDetail;
import com.exp.tracker.data.model.ExpenseSearchCriteria;
import com.exp.tracker.data.model.SettlementBean;
import com.exp.tracker.data.model.UserBean;
import com.exp.tracker.data.model.UserShare;
import com.exp.tracker.services.api.ExpenseService;
import com.exp.tracker.services.api.UserService;

public class JpaExpenseServiceTests extends AbstractExpenseTrackerBaseTest
{

	static JdbcDaoImpl userDetailService;
	
	@Autowired private ExpenseService expenseService;
	
	@Autowired private UserService userService;
	
	@Autowired
	ApplicationContext ctx;
	
	private ExpenseDetail expenseDetail;
	@Before
    public void setup() {
		userDetailService = ctx.getBean(JdbcDaoImpl.class);
		UserDetails userDetails = userDetailService.loadUserByUsername("Admin");
		Authentication authToken = new UsernamePasswordAuthenticationToken(
				userDetails.getUsername(), userDetails.getPassword(),
				userDetails.getAuthorities());
		SecurityContextHolder.getContext().setAuthentication(authToken);
		
		// Add 1st user
        UserBean ub1 = new UserBean();
        ub1.setEmailId("<EMAIL>");
        ub1.setEnabled(true);
        ub1.setFirstName("Test1");
        ub1.setLastName("User1");
        ub1.setMiddleInit("1");
        ub1.setPassword("password");
        ub1.setUsername("testuser1");      
        UserBean userBean1 = userService.addUser(ub1);
        Assert.assertNotNull("Failed to create user1. Why", userBean1);
        //
        // Add 1st user
        UserBean ub2 = new UserBean();
        ub2.setEmailId("<EMAIL>");
        ub2.setEnabled(true);
        ub2.setFirstName("Test2");
        ub2.setLastName("User2");
        ub2.setMiddleInit("2");
        ub2.setPassword("password");
        ub2.setUsername("testuser2");      
        UserBean userBean2 = userService.addUser(ub2);
        Assert.assertNotNull("Failed to create user2", userBean2);
        // Setup an expense
		ExpenseDetail ed = new ExpenseDetail();
		ed.setAmount(20.0F);
		ed.setCategory("Somecategory");
		ed.setCreatedBy("Admin");
		ed.setDate(new Date());
		ed.setDescription("Some Expense");
		ed.setPaidBy("testuser1");
		ed.setSettlementId(null);
		// now set shares
		UserShare us1 = new UserShare("testuser1", 10.0F, 0.0F, true);
		UserShare us2 = new UserShare("testuser2", 10.0F, 0.0F, true);
		ed.getUserShares().add(us1);
		ed.getUserShares().add(us2);
		//
		expenseDetail = ed;
		
	}
	
	@Test
	public void expenseRelatedTests() {
		// Check if expense was saved earlier
		Assert.assertNotNull("Expense detail is null",expenseDetail);
		int result = expenseService.saveExpense(expenseDetail);
		Assert.assertTrue("Failed to save expense.", result == 0);
		
		
		// Search for expenses in a date range
		ExpenseSearchCriteria esc = new ExpenseSearchCriteria();
		Date today = new Date();
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(today);
		cal1.add(Calendar.DAY_OF_MONTH, -1);<commit_msg>Garbage tests<commit_after>package com.exp.tracker.services.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl;

import com.exp.tracker.data.entities.ExpenseEntity;
import com.exp.tracker.data.model.ExpenseDetail;
import com.exp.tracker.data.model.ExpenseSearchCriteria;
import com.exp.tracker.data.model.SettlementBean;
import com.exp.tracker.data.model.UserBean;
import com.exp.tracker.data.model.UserShare;
import com.exp.tracker.services.api.ExpenseService;
import com.exp.tracker.services.api.UserService;

public class JpaExpenseServiceTests extends AbstractExpenseTrackerBaseTest
{

	static JdbcDaoImpl userDetailService;
	
	@Autowired private ExpenseService expenseService;
	
	@Autowired private UserService userService;
	
	@Autowired
	ApplicationContext ctx;
	
	private ExpenseDetail expenseDetail;
	@Before
    public void setup() {
		userDetailService = ctx.getBean(JdbcDaoImpl.class);
		UserDetails userDetails = userDetailService.loadUserByUsername("Admin");
		Authentication authToken = new UsernamePasswordAuthenticationToken(
				userDetails.getUsername(), userDetails.getPassword(),
				userDetails.getAuthorities());
		SecurityContextHolder.getContext().setAuthentication(authToken);
		
		// Add 1st user
        UserBean ub1 = new UserBean();
        ub1.setEmailId("<EMAIL>");
        ub1.setEnabled(true);
        ub1.setFirstName("Test1");
        ub1.setLastName("User1");
        ub1.setMiddleInit("1");
        ub1.setPassword("password");
        ub1.setUsername("testuser1");      
        UserBean userBean1 = userService.addUser(ub1);
        Assert.assertNotNull("Failed to create user1. Why", userBean1);
        //
        // Add 1st user
        UserBean ub2 = new UserBean();
        ub2.setEmailId("<EMAIL>");
        ub2.setEnabled(true);
        ub2.setFirstName("Test2");
        ub2.setLastName("User2");
        ub2.setMiddleInit("2");
        ub2.setPassword("password");
        ub2.setUsername("testuser2");      
        UserBean userBean2 = userService.addUser(ub2);
        Assert.assertNotNull("Failed to create user2", userBean2);
        // Setup an expense
		ExpenseDetail ed = new ExpenseDetail();
		ed.setAmount(20.0F);
		ed.setCategory("Somecategory");
		ed.setCreatedBy("Admin");
		ed.setDate(new Date());
		ed.setDescription("Some Expense");
		ed.setPaidBy("testuser1");
		ed.setSettlementId(null);
		// now set shares
		UserShare us1 = new UserShare("testuser1", 10.0F, 0.0F, true);
		UserShare us2 = new UserShare("testuser2", 10.0F, 0.0F, true);
		ed.getUserShares().add(us1);
		ed.getUserShares().add(us2);
		//
		expenseDetail = ed;
		
	}
	
	@Test
	public void expenseRelatedTests() {
		// Check if expense was saved earlier
		Assert.assertNotNull("Expense detail is null",expenseDetail);
		int result = expenseService.saveExpense(expenseDetail);
		Assert.assertTrue("Failed to save expense.", result == 0);
		
		// Search for expenses in a date range
		ExpenseSearchCriteria esc = new ExpenseSearchCriteria();
		Date today = new Date();
		Calendar cal1 = Calendar.getInstance();
		cal1.setTime(today);
		cal1.add(Calendar.DAY_OF_MONTH, -1);
{'fraction_non_alphanumeric': 0.11587107303141575, 'fraction_numerical': 0.016047871617027063, 'mean_word_length': 4.279253409906676, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '7393305', 'n_tokens_mistral': 2327, 'n_tokens_neox': 2209, 'n_words': 418}