Skip to content
This repository has been archived by the owner on Jun 20, 2018. It is now read-only.

Commit

Permalink
#77 - implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
vlsidlyarevich committed Jun 13, 2017
1 parent 59dc97e commit 1d9feae
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
import com.github.vlsidlyarevich.unity.db.domain.UserAnalytics;
import com.github.vlsidlyarevich.unity.db.domain.UserSocial;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public final class TestUtils {
Expand All @@ -21,6 +23,10 @@ public static UserAnalytics createUserAnalytics() {
return new UserAnalytics(TestRandomUtils.getRandomString(8), reports);
}

public static AnalysisReport createAnalysisReport() {
return new AnalysisReport(null, new Date(), 1L);
}

public static User createUser() {
List<Authority> authorities = new ArrayList<>();
authorities.add(Authority.ROLE_USER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.vlsidlyarevich.unity.db.service;

import com.github.vlsidlyarevich.unity.common.model.AnalysisReport;
import com.github.vlsidlyarevich.unity.db.UnityDatabaseTest;
import com.github.vlsidlyarevich.unity.db.domain.UserAnalytics;
import org.junit.After;
Expand All @@ -11,9 +12,11 @@
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import static com.github.vlsidlyarevich.unity.db.TestUtils.createAnalysisReport;
import static com.github.vlsidlyarevich.unity.db.TestUtils.createUserAnalytics;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;

@RunWith(SpringRunner.class)
@SpringBootTest(classes = UnityDatabaseTest.class)
Expand All @@ -39,17 +42,12 @@ public void add_Success_IfValid() throws Exception {
userAnalyticsService.add(userAnalytics);

Assert.assertThat(userAnalyticsService.findAll().size(), is(1));
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), notNullValue());
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), is(userAnalytics));
}

@Test(expected = IllegalArgumentException.class)
public void add_ExceptionThrown_IfNull() throws Exception {
UserAnalytics userAnalytics = createUserAnalytics();

userAnalyticsService.add(userAnalytics);

Assert.assertThat(userAnalyticsService.findAll().size(), is(1));
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), notNullValue());
userAnalyticsService.add(null);
}

@Test
Expand All @@ -65,11 +63,9 @@ public void find_Success_IfPresent() throws Exception {
@Test
public void find_Null_IfNotPresent() throws Exception {
UserAnalytics userAnalytics = createUserAnalytics();
userAnalytics.setId("id");

userAnalyticsService.add(userAnalytics);

Assert.assertThat(userAnalyticsService.findAll().size(), is(1));
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), notNullValue());
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), nullValue());
}

@Test
Expand All @@ -78,18 +74,14 @@ public void findByUserId_Success_IfPresent() throws Exception {

userAnalyticsService.add(userAnalytics);

Assert.assertThat(userAnalyticsService.findAll().size(), is(1));
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), notNullValue());
Assert.assertThat(userAnalyticsService.findByUserId(userAnalytics.getUserId()), is(userAnalytics));
}

@Test
public void findByUserId_Null_IfNotPresent() throws Exception {
UserAnalytics userAnalytics = createUserAnalytics();

userAnalyticsService.add(userAnalytics);

Assert.assertThat(userAnalyticsService.findAll().size(), is(1));
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), notNullValue());
Assert.assertThat(userAnalyticsService.findByUserId(userAnalytics.getUserId()), nullValue());
}

@Test
Expand All @@ -99,32 +91,28 @@ public void findAll_Success_IfPresent() throws Exception {
userAnalyticsService.add(userAnalytics);

Assert.assertThat(userAnalyticsService.findAll().size(), is(1));
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), notNullValue());
Assert.assertTrue(userAnalyticsService.findAll().contains(userAnalytics));
}

@Test
public void findAll_Empty_IfNotPresent() throws Exception {
UserAnalytics userAnalytics = createUserAnalytics();

userAnalyticsService.add(userAnalytics);

Assert.assertThat(userAnalyticsService.findAll().size(), is(1));
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), notNullValue());
Assert.assertTrue(userAnalyticsService.findAll().isEmpty());
}

@Test
public void delete_Success_IfPresent() throws Exception {
UserAnalytics userAnalytics = createUserAnalytics();

userAnalyticsService.add(userAnalytics);
userAnalyticsService.delete(userAnalytics.getId());

Assert.assertThat(userAnalyticsService.findAll().size(), is(1));
Assert.assertThat(userAnalyticsService.find(userAnalytics.getId()), notNullValue());
Assert.assertTrue(userAnalyticsService.findAll().isEmpty());
}

@Test
public void deleteReport_Success_IfPresent() throws Exception {
UserAnalytics userAnalytics = createUserAnalytics();
AnalysisReport analysisReport = createAnalysisReport();

userAnalyticsService.add(userAnalytics);

Expand Down

0 comments on commit 1d9feae

Please sign in to comment.