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 Tests to DoiCleanup #8124

Merged
merged 12 commits into from
Oct 7, 2021
122 changes: 122 additions & 0 deletions src/test/java/org/jabref/logic/cleanup/DoiCleanupTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package org.jabref.logic.cleanup;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.StandardField;
import org.jabref.model.entry.field.UnknownField;

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

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

public class DoiCleanupTest {

private BibEntry expected;

@BeforeEach
public void setUp() {
expected = new BibEntry()
.withField(StandardField.DOI, "10.1145/2594455");
}

@Test
void cleanupDoiEntryJustDoi() {

BibEntry input = new BibEntry()
.withField(StandardField.DOI, "10.1145/2594455");

DoiCleanup cleanup = new DoiCleanup();
cleanup.cleanup(input);

assertEquals(expected, input);
}

@Test
void cleanupDoiEntryJustDoiAllEntries() {

UnknownField unknownField = new UnknownField("ee");

BibEntry input = new BibEntry()
.withField(StandardField.DOI, "10.1145/2594455")
.withField(StandardField.URL, "https://doi.org/10.1145/2594455")
.withField(StandardField.NOTE, "https://doi.org/10.1145/2594455")
.withField(unknownField, "https://doi.org/10.1145/2594455");

DoiCleanup cleanup = new DoiCleanup();
cleanup.cleanup(input);

assertEquals(expected, input);
}

@Test
void cleanupDoiEntryDoiFieldsWithoutHttp() {

UnknownField unknownField = new UnknownField("ee");

BibEntry input = new BibEntry()
.withField(StandardField.DOI, "10.1145/2594455")
.withField(StandardField.NOTE, "This is a random note to this Doi")
.withField(unknownField, "This is a random ee field for this Doi");

BibEntry output = new BibEntry()
.withField(StandardField.DOI, "10.1145/2594455")
.withField(StandardField.NOTE, "This is a random note to this Doi")
.withField(unknownField, "This is a random ee field for this Doi");

DoiCleanup cleanup = new DoiCleanup();
cleanup.cleanup(input);

assertEquals(output, input);
}

@Test
void cleanupDoiEntryDoiWithSpaces() {

BibEntry input = new BibEntry()
.withField(StandardField.DOI, "10.1145 / 2594455");

DoiCleanup cleanup = new DoiCleanup();
cleanup.cleanup(input);

assertEquals(expected, input);
}

@Test
void cleanupDoiJustUrl() {

BibEntry input = new BibEntry()
.withField(StandardField.URL, "https://doi.org/10.1145/2594455");

DoiCleanup cleanup = new DoiCleanup();
cleanup.cleanup(input);

assertEquals(expected, input);
}

@Test
void cleanupDoiJustNote() {

BibEntry input = new BibEntry()
.withField(StandardField.NOTE, "https://doi.org/10.1145/2594455");

DoiCleanup cleanup = new DoiCleanup();
cleanup.cleanup(input);

assertEquals(expected, input);
}

@Test
void cleanupDoiJustEe() {

UnknownField unknownField = new UnknownField("ee");

BibEntry input = new BibEntry()
.withField(unknownField, "https://doi.org/10.1145/2594455");

DoiCleanup cleanup = new DoiCleanup();
cleanup.cleanup(input);

assertEquals(expected, input);
}

}