Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more unit tests #7649

Merged
merged 2 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/test/java/org/jabref/gui/util/ColorUtilTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jabref.gui.util;

import javafx.scene.paint.Color;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ColorUtilTest {

private ColorUtil colorUtil = new ColorUtil();
private final Color c1 = Color.color(0.2, 0.4, 1);
private final Color c2 = Color.rgb(255, 255, 255);

@Test
public void toRGBCodeTest() {
assertEquals("#3366FF", ColorUtil.toRGBCode(c1));
assertEquals("#FFFFFF", ColorUtil.toRGBCode(c2));
}

@Test
public void toHexTest() {
assertEquals("#000001", ColorUtil.toHex(c1));
assertEquals("#010101", ColorUtil.toHex(c2));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package org.jabref.gui.util.comparator;

import java.util.Optional;

import org.jabref.gui.specialfields.SpecialFieldValueViewModel;
import org.jabref.model.entry.field.SpecialFieldValue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class RankingFieldComparatorTest {

private RankingFieldComparator comparator;
private final SpecialFieldValue value1 = SpecialFieldValue.RANK_1;
private final SpecialFieldValue value2 = SpecialFieldValue.RANK_2;
private final SpecialFieldValue value3 = SpecialFieldValue.RANK_3;
private final Optional<SpecialFieldValueViewModel> rank1 = Optional.of(new SpecialFieldValueViewModel(value1));
private final Optional<SpecialFieldValueViewModel> rank2 = Optional.of(new SpecialFieldValueViewModel(value2));
private final Optional<SpecialFieldValueViewModel> rank3 = Optional.of(new SpecialFieldValueViewModel(value3));

@BeforeEach
public void setUp() {
comparator = new RankingFieldComparator();
}

@Test
public void compareHigherRankFirst() {
assertEquals(-2, comparator.compare(rank3, rank1));
assertEquals(-1, comparator.compare(rank2, rank1));
}

@Test
public void compareLowerRankFirst() {
assertEquals(1, comparator.compare(rank1, rank2));
assertEquals(2, comparator.compare(rank1, rank3));
}

@Test
public void compareSameRank() {
assertEquals(0, comparator.compare(rank1, rank1));
}

@Test
public void compareTwoEmptyInputs() {
assertEquals(0, comparator.compare(Optional.empty(), Optional.empty()));
}

@Test
public void compareTwoInputsWithFirstEmpty() {
assertEquals(1, comparator.compare(Optional.empty(), rank1));
}

@Test
public void compareTwoInputsWithSecondEmpty() {
assertEquals(-1, comparator.compare(rank1, Optional.empty()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package org.jabref.gui.util.comparator;

import java.util.Optional;

import org.jabref.gui.specialfields.SpecialFieldValueViewModel;
import org.jabref.model.entry.field.SpecialFieldValue;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class SpecialFieldComparatorTest {

private SpecialFieldComparator comparator;
private final SpecialFieldValue value1 = SpecialFieldValue.PRIORITY_HIGH;
private final SpecialFieldValue value2 = SpecialFieldValue.PRIORITY_LOW;
private final SpecialFieldValue value3 = SpecialFieldValue.READ;
private final Optional<SpecialFieldValueViewModel> prio1 = Optional.of(new SpecialFieldValueViewModel(value1));
private final Optional<SpecialFieldValueViewModel> prio3 = Optional.of(new SpecialFieldValueViewModel(value2));
private final Optional<SpecialFieldValueViewModel> read = Optional.of(new SpecialFieldValueViewModel(value3));

@BeforeEach
public void setUp() {
comparator = new SpecialFieldComparator();
}

@Test
public void compareHigherPriorityFirst() {
assertEquals(-2, comparator.compare(prio1, prio3));
}

@Test
public void compareLowerPriorityFirst() {
assertEquals(2, comparator.compare(prio3, prio1));
}

@Test
public void compareSamePriority() {
assertEquals(0, comparator.compare(prio1, prio1));
}

@Test
public void compareUnrelatedFields() {
assertEquals(-11, comparator.compare(prio1, read));
}

@Test
public void compareTwoEmptyInputs() {
assertEquals(0, comparator.compare(Optional.empty(), Optional.empty()));
}

@Test
public void compareTwoInputsWithFirstEmpty() {
assertEquals(1, comparator.compare(Optional.empty(), prio1));
}

@Test
public void compareTwoInputsWithSecondEmpty() {
assertEquals(-1, comparator.compare(prio1, Optional.empty()));
}
}