Skip to content

Commit

Permalink
Fixed code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
w3stling committed Aug 30, 2023
1 parent e76ad58 commit 123c4f4
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,59 +9,59 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class MapperTest {
class MapperTest {

@ParameterizedTest
@ValueSource(strings = {"true", "TRUE", "True", "yes", "YES", "Yes"})
public void testMapBooleanTrue(String trueValue) {
void testMapBooleanTrue(String trueValue) {
Item item = new Item(new DateTime());
Mapper.mapBoolean(trueValue, item::setIsPermaLink);
assertEquals(true, item.getIsPermaLink().orElse(null));
}

@ParameterizedTest
@ValueSource(strings = {"false", "FALSE", "False", "no", "NO", "No"})
public void testMapBooleanFalse(String falseValue) {
void testMapBooleanFalse(String falseValue) {
Item item = new Item(new DateTime());
Mapper.mapBoolean(falseValue, item::setIsPermaLink);
assertEquals(false, item.getIsPermaLink().orElse(null));
}

@ParameterizedTest
@ValueSource(strings = {"1", "-1", "0", "12345", "-12345"})
public void testMapInt(String intTextValue) {
void testMapInt(String intTextValue) {
Image image = new Image();
Mapper.mapInteger(intTextValue, image::setHeight);
assertEquals(Integer.valueOf(intTextValue), image.getHeight().orElse(null));
}

@ParameterizedTest
@ValueSource(strings = {"aaa", "a1", "1a"})
public void testMapBadInt(String intTextValue) {
void testMapBadInt(String intTextValue) {
Image image = new Image();
Mapper.mapInteger(intTextValue, image::setHeight);
assertTrue(image.getHeight().isEmpty());
}

@ParameterizedTest
@ValueSource(strings = {"1", "-1", "0", "12345", "-12345"})
public void testMapLong(String longTextValue) {
void testMapLong(String longTextValue) {
Enclosure enclosure = new Enclosure();
Mapper.mapLong(longTextValue, enclosure::setLength);
assertEquals(Long.valueOf(longTextValue), enclosure.getLength().orElse(null));
}

@ParameterizedTest
@ValueSource(strings = {"aaa", "a1", "1a"})
public void testMapBadLong(String longTextValue) {
void testMapBadLong(String longTextValue) {
Enclosure enclosure = new Enclosure();
Mapper.mapLong(longTextValue, enclosure::setLength);
assertTrue(enclosure.getLength().isEmpty());
}


@Test
public void testCreateIfNull() {
void testCreateIfNull() {
Channel channel = new Channel(new DateTime());
Mapper.createIfNull(channel::getImage, channel::setImage, Image::new).setTitle("title");
assertEquals("title", channel.getImage().map(Image::getTitle).orElse("-"));
Expand All @@ -71,7 +71,7 @@ public void testCreateIfNull() {
}

@Test
public void testCreateIfNullOptional() {
void testCreateIfNullOptional() {
Channel channel = new Channel(new DateTime());
Mapper.createIfNullOptional(channel::getImage, channel::setImage, Image::new).ifPresent(i -> mapInteger("200", i::setHeight));
assertEquals(200, channel.getImage().flatMap(Image::getHeight).orElse(0));
Expand Down

0 comments on commit 123c4f4

Please sign in to comment.