<commit_before>package com.gdn.x.beirut.services;

import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;

import com.gdn.common.exception.ApplicationException;
import com.gdn.x.beirut.dao.PositionDAO;
import com.gdn.x.beirut.entities.Position;

public class PositionServiceTest {

  private static final String DEFAULT_ID = "ID";

  private static final String STORE_ID = "STORE_ID";

  @Mock
  private PositionDAO repository;

  @InjectMocks
  private PositionServiceImpl service;

  @PersistenceContext
  private EntityManager em;

  private Position position;
  private final List<Position> pos = new ArrayList<Position>();



  // @Test
  // @Ignore
  // public void checkMarkForDelete() {
  // List<String> ids = new ArrayList<String>();
  // for (int i = 0; i < pos.size(); i++) {
  // ids.add(pos.get(i).getId());
  // }
  // this.service.markForDeletePosition(ids);
  // Mockito.verify(this.repository).findByIdAndMarkForDelete(this.position.getId(), false);
  // }


  @Test
  public void checkUpdatePositionTitle() {
    this.service.updatePositionTitle(this.position.getId(), "<NAME>");
    verify(this.repository).findOne(this.position.getId());
    verify(this.repository).save(position);
  }

  @Test
  public void getPositionByTitle() {
    this.service.getPositionByTitle("Cho", "Store");
    verify(this.repository).findByTitleContainingAndStoreIdAndMarkForDelete("Cho", "Store", false);
  }

  @Before
  public void initialize() throws Exception {
    initMocks(this);
    this.position = new Position();
    this.position.setTitle("Choa");
    this.position.setId("122");
    this.position.setStoreId("Store");
    pos.add(this.position);
    this.repository.save(this.position);
    Mockito.when(this.repository
        .findByTitleContainingAndStoreIdAndMarkForDelete(this.position.getTitle(), "Store", false))
        .thenReturn(pos);
    Mockito.when(this.repository.save(this.position)).thenReturn(this.position);
    List<String> aa = new ArrayList<String>();
    aa.add("1");
  }

  @Test
  public void testGetAllPosition() {
    this.service.getAllPosition(STORE_ID);
    verify(this.repository, Mockito.times(1)).getAllPositionByStoreId(STORE_ID);
  }

  @Test
  public void testGetPosition() throws Exception {
    Mockito.when(repository.findOne(DEFAULT_ID)).thenReturn(position);
    this.service.getPosition(DEFAULT_ID);
    verify(this.repository).findOne(DEFAULT_ID);
  }

  @Test
  public void testGetPositionAndReturnException() throws Exception {
    Mockito.when(repository.findOne(DEFAULT_ID)).thenReturn(null);
    try {
      this.service.getPosition(DEFAULT_ID);
    } catch (Exception e) {
      if (e instanceof ApplicationException) {
        Assert.assertEquals("Can not find data :no position id = " + DEFAULT_ID, e.getMessage());
      } else {
        Assert.assertTrue(false);
      }
    }
    verify(this.repository).findOne(DEFAULT_ID);
  }

  @Test
  public void testGetPositionDetailByIdAndStoreId() throws Exception {
    Position shouldBeReturned = new Position();
    shouldBeReturned.setId(DEFAULT_ID);
    shouldBeReturned.setStoreId(STORE_ID);
    shouldBeReturned.setCreatedBy("dummy");
    shouldBeReturned.setMarkForDelete(false);
    shouldBeReturned.setTitle("This is a dummy");
    Mockito.when(repository.findByIdAndStoreIdAndMarkForDelete(DEFAULT_ID, STORE_ID, false))
        .thenReturn(shouldBeReturned);
    Position result = this.service.getPositionDetailByIdAndStoreId(DEFAULT_ID, STORE_ID);
    Mockito.verify(repository, Mockito.times(1)).findByIdAndStoreIdAndMarkForDelete(DEFAULT_ID,
        STORE_ID, false);
    Assert.assertTrue(result.equals(shouldBeReturned));
  }

  @Test
  public void testInsertNewPosition() {
    this.service.insertNewPosition(position);
    verify(this.repository, Mockito.times(2)).save(position);
  }

}<commit_msg>test insertnewposition<commit_after>package com.gdn.x.beirut.services;

import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;

import com.gdn.common.exception.ApplicationException;
import com.gdn.x.beirut.dao.PositionDAO;
import com.gdn.x.beirut.entities.Position;

public class PositionServiceTest {

  private static final String DEFAULT_ID = "ID";

  private static final String STORE_ID = "STORE_ID";

  @Mock
  private PositionDAO repository;

  @InjectMocks
  private PositionServiceImpl service;

  @PersistenceContext
  private EntityManager em;

  private Position position;
  private final List<Position> pos = new ArrayList<Position>();



  // @Test
  // @Ignore
  // public void checkMarkForDelete() {
  // List<String> ids = new ArrayList<String>();
  // for (int i = 0; i < pos.size(); i++) {
  // ids.add(pos.get(i).getId());
  // }
  // this.service.markForDeletePosition(ids);
  // Mockito.verify(this.repository).findByIdAndMarkForDelete(this.position.getId(), false);
  // }


  @Test
  public void checkUpdatePositionTitle() {
    this.service.updatePositionTitle(this.position.getId(), "<NAME>");
    verify(this.repository).findOne(this.position.getId());
    verify(this.repository).save(position);
  }

  @Test
  public void getPositionByTitle() {
    this.service.getPositionByTitle("Cho", "Store");
    verify(this.repository).findByTitleContainingAndStoreIdAndMarkForDelete("Cho", "Store", false);
  }

  @Before
  public void initialize() throws Exception {
    initMocks(this);
    this.position = new Position();
    this.position.setTitle("Choa");
    this.position.setId("122");
    this.position.setStoreId("Store");
    pos.add(this.position);
    this.repository.save(this.position);
    Mockito.when(this.repository
        .findByTitleContainingAndStoreIdAndMarkForDelete(this.position.getTitle(), "Store", false))
        .thenReturn(pos);
    Mockito.when(this.repository.save(this.position)).thenReturn(this.position);
    List<String> aa = new ArrayList<String>();
    aa.add("1");
  }

  @Test
  public void testGetAllPosition() {
    this.service.getAllPosition(STORE_ID);
    verify(this.repository, Mockito.times(1)).getAllPositionByStoreId(STORE_ID);
  }

  @Test
  public void testGetPosition() throws Exception {
    Mockito.when(repository.findOne(DEFAULT_ID)).thenReturn(position);
    this.service.getPosition(DEFAULT_ID);
    verify(this.repository).findOne(DEFAULT_ID);
  }

  @Test
  public void testGetPositionAndReturnException() throws Exception {
    Mockito.when(repository.findOne(DEFAULT_ID)).thenReturn(null);
    try {
      this.service.getPosition(DEFAULT_ID);
    } catch (Exception e) {
      if (e instanceof ApplicationException) {
        Assert.assertEquals("Can not find data :no position id = " + DEFAULT_ID, e.getMessage());
      } else {
        Assert.assertTrue(false);
      }
    }
    verify(this.repository).findOne(DEFAULT_ID);
  }

  @Test
  public void testGetPositionDetailByIdAndStoreId() throws Exception {
    Position shouldBeReturned = new Position();
    shouldBeReturned.setId(DEFAULT_ID);
    shouldBeReturned.setStoreId(STORE_ID);
    shouldBeReturned.setCreatedBy("dummy");
    shouldBeReturned.setMarkForDelete(false);
    shouldBeReturned.setTitle("This is a dummy");
    Mockito.when(repository.findByIdAndStoreIdAndMarkForDelete(DEFAULT_ID, STORE_ID, false))
        .thenReturn(shouldBeReturned);
    Position result = this.service.getPositionDetailByIdAndStoreId(DEFAULT_ID, STORE_ID);
    Mockito.verify(repository, Mockito.times(1)).findByIdAndStoreIdAndMarkForDelete(DEFAULT_ID,
        STORE_ID, false);
    Assert.assertTrue(result.equals(shouldBeReturned));
  }

  @Test
  public void testInsertNewPosition() {
    Position testSavePosition = new Position();
    testSavePosition.setId(DEFAULT_ID);
    testSavePosition.setStoreId(STORE_ID);
    testSavePosition.setTitle("Choa");
    testSavePosition.setId("122");
    testSavePosition.setStoreId("Store");
    Mockito.when(repository.save(position)).thenReturn(testSavePosition);
    boolean isSaved = this.service.insertNewPosition(position);
    Mockito.verify(repository, Mockito.times(2)).save(position);
    Assert.assertTrue(position.equals(testSavePosition));

  }

}
{'fraction_non_alphanumeric': 0.12354152367879204, 'fraction_numerical': 0.002173415694349119, 'mean_word_length': 4.533544303797468, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 17, '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': '7592649', 'n_tokens_mistral': 2700, 'n_tokens_neox': 2664, 'n_words': 444}