Skip to content

Commit

Permalink
Merge pull request #86 from justinhrobbins/feature_80
Browse files Browse the repository at this point in the history
  • Loading branch information
justinhrobbins committed Jan 7, 2014
2 parents 186ba13 + 7b51a2d commit 522e49f
Showing 1 changed file with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.robbins.flashcards.service.util;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.robbins.flashcards.dto.TagDto;
import org.robbins.flashcards.exceptions.ServiceException;
import org.robbins.tests.BaseMockingTest;
import org.robbins.tests.UnitTest;


@Category(UnitTest.class)
public class DtoUtilUT extends BaseMockingTest {

@Test
public void filterFields() throws ServiceException {
String NAME = "TEST_NAME";
TagDto tagDto = new TagDto();
tagDto.setName(NAME);
Set<String> fields = new HashSet<String>(Arrays.asList("name"));

DtoUtil.filterFields(tagDto, fields);

assertThat(tagDto.getName(), is(NAME));
}

@Test
public void filterFields_WithFields() throws ServiceException {
String NAME = "TEST_NAME";
TagDto tagDto = new TagDto(1L);
tagDto.setName(NAME);
Set<String> fields = new HashSet<String>(Arrays.asList("id"));

DtoUtil.filterFields(tagDto, fields);

assertThat(tagDto.getName(), is(nullValue()));
}

@Test
public void filterFields_WithNullFields() throws ServiceException {
String NAME = "TEST_NAME";
TagDto tagDto = new TagDto();
tagDto.setName(NAME);

DtoUtil.filterFields(tagDto, null);

assertThat(tagDto.getName(), is(NAME));
}
}

0 comments on commit 522e49f

Please sign in to comment.