eu.off.db.entity.MemberTest.java Source code

Java tutorial

Introduction

Here is the source code for eu.off.db.entity.MemberTest.java

Source

package eu.off.db.entity;

import static org.assertj.core.api.Assertions.assertThat;

import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.util.Date;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import eu.off.CountryApplication;
import eu.off.db.entity.Member.MemberBuilder;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = CountryApplication.class)
public class MemberTest {

    private static final String PORTABLE_PHONE = "";
    private static final String PHONE = "";
    private static final String EMAIL = "a@a.com";
    private static final String NATIONALITY = "BE";
    private static final String GENDER = "M";
    private static final String COUNTRY = "Belgium";
    private static final String PLACE = "Moresnet";
    private static final String ZIP_CODE = "4850";
    private static final String STREET = "Rue Arnold de Lasaulx 10";
    private static final String LAST_NAME = "Offermann";
    private static final String FIRST_NAME = "Alexander";

    @Test
    public void BuildMinimalMember() {

        LocalDateTime dateTime = LocalDateTime.of(1978, Month.APRIL, 4, 0, 0);
        Date birthday = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());

        Member aMember = new MemberBuilder(LAST_NAME, FIRST_NAME, STREET, ZIP_CODE, PLACE, COUNTRY, birthday,
                GENDER, NATIONALITY).build();

        assertThat(aMember.getLastName().equals(LAST_NAME));
        assertThat(aMember.getFirstName().equals(FIRST_NAME));
        assertThat(aMember.getAdress().equals(STREET));
        assertThat(aMember.getZipCode().equals(ZIP_CODE));
        assertThat(aMember.getPlace().equals(PLACE));
        assertThat(aMember.getCountry().equals(COUNTRY));
        assertThat(aMember.getBirthday().equals(birthday));
        assertThat(aMember.getGender().equals(GENDER));
        assertThat(aMember.getNationality().equals(NATIONALITY));
    }

    @Test
    public void BuildFullMember() {

        LocalDateTime dateTime = LocalDateTime.of(1978, Month.APRIL, 4, 0, 0);
        Date birthday = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());

        Member aMember = new MemberBuilder(LAST_NAME, FIRST_NAME, STREET, ZIP_CODE, PLACE, COUNTRY, birthday,
                GENDER, NATIONALITY).email(EMAIL).phone(PHONE).portablePhone(PORTABLE_PHONE).memberSince(birthday)
                        .licenseSince(birthday).build();

        assertThat(aMember.getEmail().equals(EMAIL));
        assertThat(aMember.getPhone().equals(PHONE));
        assertThat(aMember.getPortablePhone().equals(PORTABLE_PHONE));
        assertThat(aMember.getMemberSince().equals(birthday));
        assertThat(aMember.getLicenseSince().equals(birthday));

    }
}