Skip to content

Commit

Permalink
Quick sketch of how the CSVreader would read in data and use it in au…
Browse files Browse the repository at this point in the history
…tomated

automated test. The examples are written in the tests methods. This is
related to issue JabRef#6189.
  • Loading branch information
David Yu authored and David Yu committed Mar 8, 2021
1 parent 6b16f6f commit 621c036
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
26 changes: 26 additions & 0 deletions src/main/java/org/jabref/logic/journals/JournalStatistics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.jabref.logic.journals;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class JournalStatistics {
private Path pathToCSV;

public JournalStatistics(Path path) {
this.pathToCSV = path;
}

public boolean getTitleByISSN(int ISSN) throws IOException {
String readString = Files.readString(pathToCSV);
String[] strings = readString.split(";");

for (String s:
strings) {
if (s.contains(String.valueOf(ISSN))) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
package org.jabref.gui.fieldeditors;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
import java.util.Optional;

import org.jabref.logic.journals.JournalStatistics;

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

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

class JournalEditorPopOverTest {

private Path tempFolder;
private final String testEntry = "1, 28773, CA - A Cancer Journal for Clinicians, journal, 15424863, 00079235, 88,192, Q1, 156, 36, 129, 2924, 22644, 89, 255.73, 81.22, United States, Northern America, Wiley-Blackwell, 1950-2020, Hematology (Q1); Oncology (Q1)";
private final String testEntry = "1;28773;CA - A Cancer Journal for Clinicians;journal;15424863, 00079235;88,192;Q1;156;36;129;2924;22644;89;255,73;81,22;United States;Northern America;Wiley-Blackwell;1950-2020;Hematology (Q1), Oncology (Q1)";
private JournalStatistics jsReader;
// Create object that loads in data from file

/**
Expand All @@ -43,11 +45,14 @@ void testValidISSN() throws IOException {
Files.writeString(file,
testEntry, StandardOpenOption.CREATE); // Write the test entry to temp file

int ISSN = 15424863;

jsReader = new JournalStatistics(file);
// Call method with valid ISSN with the object created during setup
String expectedJournalName = ""; // This variable should hold a method call to finding the correct journal given a valid ISSN
boolean found = jsReader.getTitleByISSN(ISSN); // This variable should hold a method call to finding the correct journal given a valid ISSN
String trueJournalName = "CA - A Cancer Journal for Clinicians"; // true title of the found journal

assertEquals(trueJournalName, expectedJournalName);
assertTrue(found);
}

/**
Expand All @@ -60,11 +65,15 @@ void testInvalidISSN() throws IOException {
Files.writeString(file,
testEntry, StandardOpenOption.CREATE); // Write test entry to temp file

int ISSN = 12300000;

jsReader = new JournalStatistics(file);
boolean found = jsReader.getTitleByISSN(ISSN);
// Call method with invalid ISSN with the object created during setup
String expectedJournalName = ""; // This variable is suppose to hold the title of the journal for the invalid ISSN
String trueJournalName = "Nature Reviews Genetics"; // Or empty String

assertEquals(expectedJournalName, trueJournalName);
assertFalse(found);
}

/**
Expand Down

0 comments on commit 621c036

Please sign in to comment.