<commit_before>package io.oasp.gastronomy.restaurant.offermanagement.logic.impl;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import io.oasp.gastronomy.restaurant.offermanagement.dataaccess.api.OfferEntity;
import io.oasp.gastronomy.restaurant.offermanagement.dataaccess.api.dao.OfferDao;
import io.oasp.gastronomy.restaurant.offermanagement.logic.api.to.OfferCto;
import io.oasp.gastronomy.restaurant.offermanagement.logic.api.to.OfferEto;
import io.oasp.module.beanmapping.common.api.BeanMapper;
import io.oasp.module.test.common.base.ModuleTest;

/**
 * TODO shuber This type ...
 *
 * @author shuber
 * @since dev
 */

@RunWith(MockitoJUnitRunner.class)
public class OffermanagementImplTest extends ModuleTest {

  /**
   * The System Under Test (SUT)
   */

  private OffermanagementImpl offerManagementImpl;

  @Mock
  private OffermanagementImpl offerManagementImpl2;

  @Mock
  private OfferDao offerDao;

  @Mock
  private BeanMapper beanMapper;

  @Before
  public void setup() {

    assertThat(this.offerDao).isNotNull();
    assertThat(this.beanMapper).isNotNull();
    this.offerManagementImpl = new OffermanagementImpl();
    this.offerManagementImpl.setOfferDao(this.offerDao);
    this.offerManagementImpl.setBeanMapper(this.beanMapper);
  }

  @After
  public void tearDown() {

    this.beanMapper = null;
    this.offerDao = null;
    this.offerManagementImpl = null;
  }

  @Test
  public void findOffer() {

    // setup
    // given
    long id = 1L;

    OfferEntity entity = Mockito.mock(OfferEntity.class);
    OfferEto eto = new OfferEto();

    Mockito.when(this.offerDao.findOne(id)).thenReturn(entity);
    Mockito.when(this.beanMapper.map(entity, OfferEto.class)).thenReturn(eto);

    // exercise
    // when
    OfferEto resultEto = this.offerManagementImpl.findOffer(id);

    // verify
    // then
    Mockito.verify(this.offerDao).findOne(id);
    Mockito.verify(this.beanMapper).map(entity, OfferEto.class);

    assertThat(resultEto).isNotNull();
    assertThat(resultEto).isEqualTo(eto);
  }

  @Test
  public void findOfferCto() {

    // setup
    // given
    long id = 1L;

    OfferCto offerCto = new OfferCto();
    OfferEto offerEto = new OfferEto();
    // OfferEto offerEto = Mockito.mock(OfferEto.class);
    offerCto.setOffer(offerEto);
    OfferEntity entity = Mockito.mock(OfferEntity.class);

    Mockito.when(this.offerDao.findOne(id)).thenReturn(entity);
    Mockito.when(this.beanMapper.map(entity, OfferEto.class)).thenReturn(offerEto);

    // exercise
    // when
    OfferCto resultCto = this.offerManagementImpl.findOfferCto(id);

    // verify
    // then
    Mockito.verify(this.offerDao).findOne(id);
    Mockito.verify(this.beanMapper).map(entity, OfferEto.class);

    assertThat(resultCto).isNotNull();
    assertThat(resultCto).isEqualTo(offerCto);

  }

}<commit_msg>OffermanagementImplTest.java finalized and commented via javadocs<commit_after>package io.oasp.gastronomy.restaurant.offermanagement.logic.impl;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;

import io.oasp.gastronomy.restaurant.offermanagement.dataaccess.api.OfferEntity;
import io.oasp.gastronomy.restaurant.offermanagement.dataaccess.api.dao.OfferDao;
import io.oasp.gastronomy.restaurant.offermanagement.logic.api.to.OfferCto;
import io.oasp.gastronomy.restaurant.offermanagement.logic.api.to.OfferEto;
import io.oasp.module.beanmapping.common.api.BeanMapper;
import io.oasp.module.test.common.base.ModuleTest;

/**
 * This class tests the correct execution of the methods findOffer and findOfferCto belonging to the
 * {@link OffermanagementImpl}
 *
 * @author shuber
 */

@RunWith(MockitoJUnitRunner.class)
public class OffermanagementImplTest extends ModuleTest {

  private static final long ID = 1;

  /**
   * The System Under Test (SUT)
   */

  private OffermanagementImpl offerManagementImpl;

  @Mock
  private OfferDao offerDao;

  @Mock
  private BeanMapper beanMapper;

  /**
   * This method initializes the object {@link OffermanagementImpl} and assigns the mocked objects of the classes
   * {@link OfferDao} and {@link BeanMapper} to the attributes of the {@link OffermanagementImpl} object before tests,
   * if they are not null.
   */
  @Before
  public void init() {

    assertThat(this.offerDao).isNotNull();
    assertThat(this.beanMapper).isNotNull();
    this.offerManagementImpl = new OffermanagementImpl();
    this.offerManagementImpl.setOfferDao(this.offerDao);
    this.offerManagementImpl.setBeanMapper(this.beanMapper);
  }

  /**
   * This method dereferences all object after each test
   */
  @After
  public void clean() {

    this.beanMapper = null;
    this.offerDao = null;
    this.offerManagementImpl = null;
  }

  /**
   * This method tests the execution of the findOffer method belonging to the {@link OffermanagementImpl} class
   */
  @Test
  public void findOffer() {

    // given
    OfferEntity offerEntity = Mockito.mock(OfferEntity.class);
    OfferEto offerEto = new OfferEto();

    Mockito.when(this.offerDao.findOne(ID)).thenReturn(offerEntity);
    Mockito.when(this.beanMapper.map(offerEntity, OfferEto.class)).thenReturn(offerEto);

    // when
    OfferEto responseOfferEto = this.offerManagementImpl.findOffer(ID);

    // then
    Mockito.verify(this.offerDao).findOne(ID);
    Mockito.verify(this.beanMapper).map(offerEntity, OfferEto.class);

    assertThat(responseOfferEto).isNotNull();
    assertThat(responseOfferEto).isEqualTo(offerEto);
  }

  /**
   * This method tests the execution of the findOfferCto method belonging to the {@link OffermanagementImpl} class
   */
  @Test
  public void findOfferCto() {

    // given
    OfferCto offerCto = new OfferCto();
    OfferEto offerEto = new OfferEto();

    offerCto.setOffer(offerEto);
    OfferEntity offerEntity = Mockito.mock(OfferEntity.class);

    Mockito.when(this.offerDao.findOne(ID)).thenReturn(offerEntity);
    Mockito.when(this.beanMapper.map(offerEntity, OfferEto.class)).thenReturn(offerEto);

    // when
    OfferCto responseOfferCto = this.offerManagementImpl.findOfferCto(ID);

    // then
    Mockito.verify(this.offerDao).findOne(ID);
    Mockito.verify(this.beanMapper).map(offerEntity, OfferEto.class);

    assertThat(responseOfferCto).isNotNull();
    assertThat(responseOfferCto.getOffer()).isEqualTo(offerEto);

  }

}
{'fraction_non_alphanumeric': 0.11268667974053402, 'fraction_numerical': 0.0006034092623321768, 'mean_word_length': 4.123647604327666, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6083402', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2181, 'n_words': 382}