From 9355451feb384240cdc4934a0a958b94e04b486b Mon Sep 17 00:00:00 2001 From: BHamrick Date: Sun, 22 Nov 2020 17:13:00 -0800 Subject: [PATCH 01/12] Start to work on mock wordoftheday --- hs_err_pid44175.log | 21 ++++++++++++ hs_err_pid44714.log | 21 ++++++++++++ hs_err_pid46390.log | 21 ++++++++++++ hs_err_pid46524.log | 21 ++++++++++++ .../mills/cs180a/wordui/model/SampleData.java | 22 ++++++++----- .../cs180a/wordui/model/SampleDataTest.java | 33 +++++++++++++++---- 6 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 hs_err_pid44175.log create mode 100644 hs_err_pid44714.log create mode 100644 hs_err_pid46390.log create mode 100644 hs_err_pid46524.log diff --git a/hs_err_pid44175.log b/hs_err_pid44175.log new file mode 100644 index 0000000..1393630 --- /dev/null +++ b/hs_err_pid44175.log @@ -0,0 +1,21 @@ +# +# A fatal error has been detected by the Java Runtime Environment: +# +# SIGSEGV (0xb) at pc=0x00007fbc52365375, pid=44175, tid=44191 +# +# JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18) +# Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) +# Problematic frame: +# C [libjimage.so+0x4375] ImageStrings::find(Endian*, char const*, int*, unsigned int)+0x65 +# +# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/ben/CS280A-workspace/wordui/core.44175) +# +# If you would like to submit a bug report, please visit: +# https://bugreport.java.com/bugreport/crash.jsp +# + +--------------- S U M M A R Y ------------ + +Command Line: -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:41187 --module-path=/home/ben/openjfx-15.0.1_linux-x64_bin-sdk/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/ben/eclipse/java-2020-06/eclipse/configuration/org.eclipse.osgi/537/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 edu.mills.cs180a.wordui.WordUI + +Host: \ No newline at end of file diff --git a/hs_err_pid44714.log b/hs_err_pid44714.log new file mode 100644 index 0000000..b3ef147 --- /dev/null +++ b/hs_err_pid44714.log @@ -0,0 +1,21 @@ +# +# A fatal error has been detected by the Java Runtime Environment: +# +# SIGSEGV (0xb) at pc=0x00007fefcc6c2375, pid=44714, tid=44730 +# +# JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18) +# Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) +# Problematic frame: +# C [libjimage.so+0x4375] ImageStrings::find(Endian*, char const*, int*, unsigned int)+0x65 +# +# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/ben/CS280A-workspace/wordui/core.44714) +# +# If you would like to submit a bug report, please visit: +# https://bugreport.java.com/bugreport/crash.jsp +# + +--------------- S U M M A R Y ------------ + +Command Line: -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:38895 --module-path=/home/ben/openjfx-15.0.1_linux-x64_bin-sdk/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/ben/eclipse/java-2020-06/eclipse/configuration/org.eclipse.osgi/537/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 edu.mills.cs180a.wordui.WordUI + +Host: \ No newline at end of file diff --git a/hs_err_pid46390.log b/hs_err_pid46390.log new file mode 100644 index 0000000..b96253f --- /dev/null +++ b/hs_err_pid46390.log @@ -0,0 +1,21 @@ +# +# A fatal error has been detected by the Java Runtime Environment: +# +# SIGSEGV (0xb) at pc=0x00007f6f82224375, pid=46390, tid=46407 +# +# JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18) +# Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) +# Problematic frame: +# C [libjimage.so+0x4375] ImageStrings::find(Endian*, char const*, int*, unsigned int)+0x65 +# +# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/ben/CS280A-workspace/wordui/core.46390) +# +# If you would like to submit a bug report, please visit: +# https://bugreport.java.com/bugreport/crash.jsp +# + +--------------- S U M M A R Y ------------ + +Command Line: -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:45651 --module-path=/home/ben/openjfx-15.0.1_linux-x64_bin-sdk/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/ben/eclipse/java-2020-06/eclipse/configuration/org.eclipse.osgi/537/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 edu.mills.cs180a.wordui.WordUI + +Host: \ No newline at end of file diff --git a/hs_err_pid46524.log b/hs_err_pid46524.log new file mode 100644 index 0000000..1646608 --- /dev/null +++ b/hs_err_pid46524.log @@ -0,0 +1,21 @@ +# +# A fatal error has been detected by the Java Runtime Environment: +# +# SIGSEGV (0xb) at pc=0x00007fee98246375, pid=46524, tid=46541 +# +# JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18) +# Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) +# Problematic frame: +# C [libjimage.so+0x4375] ImageStrings::find(Endian*, char const*, int*, unsigned int)+0x65 +# +# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/ben/CS280A-workspace/wordui/core.46524) +# +# If you would like to submit a bug report, please visit: +# https://bugreport.java.com/bugreport/crash.jsp +# + +--------------- S U M M A R Y ------------ + +Command Line: -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:41765 --module-path=/home/ben/openjfx-15.0.1_linux-x64_bin-sdk/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/ben/eclipse/java-2020-06/eclipse/configuration/org.eclipse.osgi/537/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 edu.mills.cs180a.wordui.WordUI + +Host: \ No newline at end of file diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index f9d8846..7031703 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -18,8 +18,16 @@ public class SampleData { @VisibleForTesting protected static final String FREQ_YEAR_KEY = "year"; private static final int FREQ_YEAR = 2012; + @VisibleForTesting + protected static final String WOD_WORD_KEY = "word"; + @VisibleForTesting + protected static final String WOD_PUBLISHDATE_KEY = "publishDate"; private static ApiClient client; // set in fillSampleData() + private static WordOfTheDay getWordOfTheDay(WordsApi wordsApi) { + return wordsApi.getWordOfTheDay(); + } + private static int getFrequencyFromSummary(FrequencySummary fs, int year) { List freqObjects = fs.getFrequency(); // freqObjects is a List [{"year" = "2012", "count" = 179}] for "Java" @@ -51,9 +59,7 @@ protected static int getFrequencyByYear(WordApi wordApi, String word, int year) private static WordRecord buildWordRecord(String word, Map definition) { WordApi wordApi = client.buildClient(WordApi.class); - return new WordRecord( - word, - getFrequencyByYear(wordApi, word, FREQ_YEAR), + return new WordRecord(word, getFrequencyByYear(wordApi, word, FREQ_YEAR), definition.get("text").toString()); } @@ -61,7 +67,7 @@ public static void fillSampleData(ObservableList backingList) { try { client = ApiClientHelper.getApiClient(); WordsApi wordsApi = client.buildClient(WordsApi.class); - WordOfTheDay word = wordsApi.getWordOfTheDay(); + WordOfTheDay word = getWordOfTheDay(wordsApi); List definitions = word.getDefinitions(); if (definitions != null && !definitions.isEmpty()) { Object definition = definitions.get(0); @@ -77,9 +83,9 @@ public static void fillSampleData(ObservableList backingList) { backingList.add(new WordRecord("buffalo", 5153, "The North American bison.")); backingList.add(new WordRecord("school", 23736, "A large group of aquatic animals.")); - backingList.add(new WordRecord("Java", - 179, "An island of Indonesia in the Malay Archipelago")); - backingList.add(new WordRecord("random", - 794, "Having no specific pattern, purpose, or objective")); + backingList.add( + new WordRecord("Java", 179, "An island of Indonesia in the Malay Archipelago")); + backingList.add( + new WordRecord("random", 794, "Having no specific pattern, purpose, or objective")); } } diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index a7808ec..84ad2e6 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -10,24 +10,35 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; +import org.mockito.Mock; import edu.mills.cs180a.wordnik.client.api.WordApi; +import edu.mills.cs180a.wordnik.client.api.WordsApi; import edu.mills.cs180a.wordnik.client.model.FrequencySummary; +import edu.mills.cs180a.wordnik.client.model.WordOfTheDay; class SampleDataTest { + + @Mock private final WordApi mockWordApi = mock(WordApi.class); - private static final Map FREQS_MAP = Map.of( - "apple", makeFrequencySummary(List.of(makeMap(2000, 339), makeMap(2001, 464))), - "orange", makeFrequencySummary(List.of(makeMap(2000, 774), makeMap(2001, 941)))); + @Mock + private final WordsApi mockWordsApi = mock(WordsApi.class); + private static final Map FREQS_MAP = Map.of("apple", + makeFrequencySummary(List.of(makeFreqMap(2000, 339), makeFreqMap(2001, 464))), "orange", + makeFrequencySummary(List.of(makeFreqMap(2000, 774), makeFreqMap(2001, 941)))); + + private static final Map WOD_MAP = + Map.of("2020-10-31", makeWODMap(List.of("2020-10-31", "spoopy"))); @BeforeEach void setup() { when(mockWordApi.getWordFrequency(anyString(), anyString(), anyInt(), anyInt())) .thenAnswer(invocation -> FREQS_MAP.get(invocation.getArgument(0))); + when(mockWordsApi.getWordOfTheDay(anyString())).thenAnswer(null); } - private static Map makeMap(int year, int count) { - return Map.of(SampleData.FREQ_YEAR_KEY, String.valueOf(year), - SampleData.FREQ_COUNT_KEY, count); + private static Map makeFreqMap(int year, int count) { + return Map.of(SampleData.FREQ_YEAR_KEY, String.valueOf(year), SampleData.FREQ_COUNT_KEY, + count); } private static FrequencySummary makeFrequencySummary(List freqs) { @@ -42,4 +53,14 @@ private static FrequencySummary makeFrequencySummary(List freqs) { void testGetFrequencyFromSummary(String word, int year, int count) { assertEquals(count, SampleData.getFrequencyByYear(mockWordApi, word, year)); } + + private static Map makeWODMap(String date, String word) { + return Map.of(SampleData.WOD_PUBLISHDATE_KEY, date, SampleData.WOD_WORD_KEY, word); + } + + private static WordOfTheDay makeWOD(List wods) { + WordOfTheDay wod = mock(WordOfTheDay.class); + when(wod.getWord()).thenReturn(wods); + return wod; + } } From d6e7a04b9c2ec2ae7038575cb3f437221d98a576 Mon Sep 17 00:00:00 2001 From: BHamrick Date: Sat, 28 Nov 2020 14:19:33 -0800 Subject: [PATCH 02/12] Mock WordOfTheDay method getWord --- .../mills/cs180a/wordui/model/SampleData.java | 2 +- .../cs180a/wordui/model/SampleDataTest.java | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index 7031703..aaa6883 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -24,7 +24,7 @@ public class SampleData { protected static final String WOD_PUBLISHDATE_KEY = "publishDate"; private static ApiClient client; // set in fillSampleData() - private static WordOfTheDay getWordOfTheDay(WordsApi wordsApi) { + protected static WordOfTheDay getWordOfTheDay(WordsApi wordsApi) { return wordsApi.getWordOfTheDay(); } diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index 84ad2e6..2a1f133 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -1,6 +1,7 @@ package edu.mills.cs180a.wordui.model; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; @@ -8,6 +9,7 @@ import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.mockito.Mock; @@ -22,18 +24,16 @@ class SampleDataTest { private final WordApi mockWordApi = mock(WordApi.class); @Mock private final WordsApi mockWordsApi = mock(WordsApi.class); + private WordOfTheDay wod = makeWOD("pepper"); private static final Map FREQS_MAP = Map.of("apple", makeFrequencySummary(List.of(makeFreqMap(2000, 339), makeFreqMap(2001, 464))), "orange", makeFrequencySummary(List.of(makeFreqMap(2000, 774), makeFreqMap(2001, 941)))); - private static final Map WOD_MAP = - Map.of("2020-10-31", makeWODMap(List.of("2020-10-31", "spoopy"))); - @BeforeEach void setup() { when(mockWordApi.getWordFrequency(anyString(), anyString(), anyInt(), anyInt())) .thenAnswer(invocation -> FREQS_MAP.get(invocation.getArgument(0))); - when(mockWordsApi.getWordOfTheDay(anyString())).thenAnswer(null); + when(mockWordsApi.getWordOfTheDay()).thenReturn(wod); } private static Map makeFreqMap(int year, int count) { @@ -54,13 +54,14 @@ void testGetFrequencyFromSummary(String word, int year, int count) { assertEquals(count, SampleData.getFrequencyByYear(mockWordApi, word, year)); } - private static Map makeWODMap(String date, String word) { - return Map.of(SampleData.WOD_PUBLISHDATE_KEY, date, SampleData.WOD_WORD_KEY, word); - } - - private static WordOfTheDay makeWOD(List wods) { + private static WordOfTheDay makeWOD(String word) { WordOfTheDay wod = mock(WordOfTheDay.class); - when(wod.getWord()).thenReturn(wods); + when(wod.getWord()).thenReturn(word); return wod; } + + @Test + void testWOD() { + assertTrue("pepper".equals(SampleData.getWordOfTheDay(mockWordsApi).getWord())); + } } From 9b1081034bdf4512088bdfde5c856ed25970980c Mon Sep 17 00:00:00 2001 From: BHamrick Date: Sat, 28 Nov 2020 14:31:07 -0800 Subject: [PATCH 03/12] Rewrite test name testing getWordOfTheDay --- .gitignore | 3 +++ .../java/edu/mills/cs180a/wordui/model/SampleDataTest.java | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 288a569..1a83767 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,6 @@ local.properties #.project /target/ api-key.txt + +#git .log +.log diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index 2a1f133..df6b0ea 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -61,7 +61,7 @@ private static WordOfTheDay makeWOD(String word) { } @Test - void testWOD() { + void getWordOfTheDay_True_CorrectWordReturned() { assertTrue("pepper".equals(SampleData.getWordOfTheDay(mockWordsApi).getWord())); } } From 3fa7cc845817f928510e8f2a025705a56edc5c92 Mon Sep 17 00:00:00 2001 From: BHamrick Date: Tue, 8 Dec 2020 12:42:52 -0800 Subject: [PATCH 04/12] Add test for getDefinitions and add mock of getDefinitions method --- .gitignore | 2 +- hs_err_pid44175.log | 21 ------------- hs_err_pid44714.log | 21 ------------- hs_err_pid46390.log | 21 ------------- hs_err_pid46524.log | 21 ------------- .../mills/cs180a/wordui/model/SampleData.java | 9 ++++-- .../cs180a/wordui/model/SampleDataTest.java | 31 ++++++++++++++++--- 7 files changed, 33 insertions(+), 93 deletions(-) delete mode 100644 hs_err_pid44175.log delete mode 100644 hs_err_pid44714.log delete mode 100644 hs_err_pid46390.log delete mode 100644 hs_err_pid46524.log diff --git a/.gitignore b/.gitignore index 1a83767..6bcc1dc 100644 --- a/.gitignore +++ b/.gitignore @@ -62,4 +62,4 @@ local.properties api-key.txt #git .log -.log +*.log diff --git a/hs_err_pid44175.log b/hs_err_pid44175.log deleted file mode 100644 index 1393630..0000000 --- a/hs_err_pid44175.log +++ /dev/null @@ -1,21 +0,0 @@ -# -# A fatal error has been detected by the Java Runtime Environment: -# -# SIGSEGV (0xb) at pc=0x00007fbc52365375, pid=44175, tid=44191 -# -# JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18) -# Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) -# Problematic frame: -# C [libjimage.so+0x4375] ImageStrings::find(Endian*, char const*, int*, unsigned int)+0x65 -# -# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/ben/CS280A-workspace/wordui/core.44175) -# -# If you would like to submit a bug report, please visit: -# https://bugreport.java.com/bugreport/crash.jsp -# - ---------------- S U M M A R Y ------------ - -Command Line: -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:41187 --module-path=/home/ben/openjfx-15.0.1_linux-x64_bin-sdk/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/ben/eclipse/java-2020-06/eclipse/configuration/org.eclipse.osgi/537/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 edu.mills.cs180a.wordui.WordUI - -Host: \ No newline at end of file diff --git a/hs_err_pid44714.log b/hs_err_pid44714.log deleted file mode 100644 index b3ef147..0000000 --- a/hs_err_pid44714.log +++ /dev/null @@ -1,21 +0,0 @@ -# -# A fatal error has been detected by the Java Runtime Environment: -# -# SIGSEGV (0xb) at pc=0x00007fefcc6c2375, pid=44714, tid=44730 -# -# JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18) -# Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) -# Problematic frame: -# C [libjimage.so+0x4375] ImageStrings::find(Endian*, char const*, int*, unsigned int)+0x65 -# -# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/ben/CS280A-workspace/wordui/core.44714) -# -# If you would like to submit a bug report, please visit: -# https://bugreport.java.com/bugreport/crash.jsp -# - ---------------- S U M M A R Y ------------ - -Command Line: -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:38895 --module-path=/home/ben/openjfx-15.0.1_linux-x64_bin-sdk/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/ben/eclipse/java-2020-06/eclipse/configuration/org.eclipse.osgi/537/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 edu.mills.cs180a.wordui.WordUI - -Host: \ No newline at end of file diff --git a/hs_err_pid46390.log b/hs_err_pid46390.log deleted file mode 100644 index b96253f..0000000 --- a/hs_err_pid46390.log +++ /dev/null @@ -1,21 +0,0 @@ -# -# A fatal error has been detected by the Java Runtime Environment: -# -# SIGSEGV (0xb) at pc=0x00007f6f82224375, pid=46390, tid=46407 -# -# JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18) -# Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) -# Problematic frame: -# C [libjimage.so+0x4375] ImageStrings::find(Endian*, char const*, int*, unsigned int)+0x65 -# -# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/ben/CS280A-workspace/wordui/core.46390) -# -# If you would like to submit a bug report, please visit: -# https://bugreport.java.com/bugreport/crash.jsp -# - ---------------- S U M M A R Y ------------ - -Command Line: -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:45651 --module-path=/home/ben/openjfx-15.0.1_linux-x64_bin-sdk/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/ben/eclipse/java-2020-06/eclipse/configuration/org.eclipse.osgi/537/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 edu.mills.cs180a.wordui.WordUI - -Host: \ No newline at end of file diff --git a/hs_err_pid46524.log b/hs_err_pid46524.log deleted file mode 100644 index 1646608..0000000 --- a/hs_err_pid46524.log +++ /dev/null @@ -1,21 +0,0 @@ -# -# A fatal error has been detected by the Java Runtime Environment: -# -# SIGSEGV (0xb) at pc=0x00007fee98246375, pid=46524, tid=46541 -# -# JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18) -# Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, linux-amd64) -# Problematic frame: -# C [libjimage.so+0x4375] ImageStrings::find(Endian*, char const*, int*, unsigned int)+0x65 -# -# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %d %P %E" (or dumping to /home/ben/CS280A-workspace/wordui/core.46524) -# -# If you would like to submit a bug report, please visit: -# https://bugreport.java.com/bugreport/crash.jsp -# - ---------------- S U M M A R Y ------------ - -Command Line: -XX:+ShowCodeDetailsInExceptionMessages -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:41765 --module-path=/home/ben/openjfx-15.0.1_linux-x64_bin-sdk/javafx-sdk-15.0.1/lib --add-modules=javafx.controls,javafx.fxml -javaagent:/home/ben/eclipse/java-2020-06/eclipse/configuration/org.eclipse.osgi/537/0/.cp/lib/javaagent-shaded.jar -Dfile.encoding=UTF-8 edu.mills.cs180a.wordui.WordUI - -Host: \ No newline at end of file diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index aaa6883..29dac6f 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -19,9 +19,6 @@ public class SampleData { protected static final String FREQ_YEAR_KEY = "year"; private static final int FREQ_YEAR = 2012; @VisibleForTesting - protected static final String WOD_WORD_KEY = "word"; - @VisibleForTesting - protected static final String WOD_PUBLISHDATE_KEY = "publishDate"; private static ApiClient client; // set in fillSampleData() protected static WordOfTheDay getWordOfTheDay(WordsApi wordsApi) { @@ -63,12 +60,18 @@ private static WordRecord buildWordRecord(String word, Map defin definition.get("text").toString()); } + /** + * Fill backing list with Word Record of the day and predefined sample words. + * + * @param backingList a list of word records that will be displayed + */ public static void fillSampleData(ObservableList backingList) { try { client = ApiClientHelper.getApiClient(); WordsApi wordsApi = client.buildClient(WordsApi.class); WordOfTheDay word = getWordOfTheDay(wordsApi); List definitions = word.getDefinitions(); + System.out.println(word.getDefinitions()); if (definitions != null && !definitions.isEmpty()) { Object definition = definitions.get(0); if (definition instanceof Map) { diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index df6b0ea..4d1b950 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -1,11 +1,11 @@ package edu.mills.cs180a.wordui.model; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; @@ -24,7 +24,11 @@ class SampleDataTest { private final WordApi mockWordApi = mock(WordApi.class); @Mock private final WordsApi mockWordsApi = mock(WordsApi.class); - private WordOfTheDay wod = makeWOD("pepper"); + private static final Map PEPPER_DEF = Map.of("text", + "A perennial climbing vine (Piper nigrum) native to India, widely cultivated for its long slender spikes of small fruit."); + private static final List DEFS = List.of(PEPPER_DEF); + private static final String PEPPER = "pepper"; + private WordOfTheDay wod = makeWOD(PEPPER, DEFS); private static final Map FREQS_MAP = Map.of("apple", makeFrequencySummary(List.of(makeFreqMap(2000, 339), makeFreqMap(2001, 464))), "orange", makeFrequencySummary(List.of(makeFreqMap(2000, 774), makeFreqMap(2001, 941)))); @@ -54,14 +58,31 @@ void testGetFrequencyFromSummary(String word, int year, int count) { assertEquals(count, SampleData.getFrequencyByYear(mockWordApi, word, year)); } - private static WordOfTheDay makeWOD(String word) { + private static WordOfTheDay makeWOD(String word, List defs) { WordOfTheDay wod = mock(WordOfTheDay.class); when(wod.getWord()).thenReturn(word); + when(wod.getDefinitions()).thenReturn(defs); return wod; } @Test - void getWordOfTheDay_True_CorrectWordReturned() { - assertTrue("pepper".equals(SampleData.getWordOfTheDay(mockWordsApi).getWord())); + void getWord_True_CorrectWordReturned() { + assertEquals("pepper", SampleData.getWordOfTheDay(mockWordsApi).getWord()); + } + + @SuppressWarnings("unchecked") + @Test + void getDefinitions_True_CorrectDefinitionsReturned() { + Map defs = copyMap(PEPPER_DEF); + assertEquals(defs, (Map) SampleData.getWordOfTheDay(mockWordsApi) + .getDefinitions().get(0)); + } + + private Map copyMap(Map originalMap) { + Map newMap = new HashMap(); + for (Object elt : originalMap.keySet()) { + newMap.put(elt, originalMap.get(elt)); + } + return newMap; } } From 02e9361810d45903e9a938ef422f40009255bda6 Mon Sep 17 00:00:00 2001 From: BHamrick Date: Wed, 9 Dec 2020 16:18:31 -0800 Subject: [PATCH 05/12] Write test for addWordOfTheDay and create addWordOfTheDay method --- .../mills/cs180a/wordui/model/SampleData.java | 35 +++++++++++-------- .../cs180a/wordui/model/SampleDataTest.java | 31 ++++++++++++---- 2 files changed, 45 insertions(+), 21 deletions(-) diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index 29dac6f..44356a4 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -21,6 +21,7 @@ public class SampleData { @VisibleForTesting private static ApiClient client; // set in fillSampleData() + @VisibleForTesting protected static WordOfTheDay getWordOfTheDay(WordsApi wordsApi) { return wordsApi.getWordOfTheDay(); } @@ -54,32 +55,38 @@ protected static int getFrequencyByYear(WordApi wordApi, String word, int year) return getFrequencyFromSummary(fs, year); } - private static WordRecord buildWordRecord(String word, Map definition) { - WordApi wordApi = client.buildClient(WordApi.class); + private static WordRecord buildWordRecord(WordApi wordApi, String word, + Map definition) { return new WordRecord(word, getFrequencyByYear(wordApi, word, FREQ_YEAR), definition.get("text").toString()); } + @VisibleForTesting + protected static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, + ObservableList backingList) { + WordOfTheDay word = getWordOfTheDay(wordsApi); + List definitions = word.getDefinitions(); + if (definitions != null && !definitions.isEmpty()) { + Object definition = definitions.get(0); + if (definition instanceof Map) { + @SuppressWarnings("unchecked") + Map definitionAsMap = (Map) definition; + backingList.add(buildWordRecord(wordApi, word.getWord(), definitionAsMap)); + } + } + } + /** - * Fill backing list with Word Record of the day and predefined sample words. + * Fill backing list with Word of the day and predefined sample words. * * @param backingList a list of word records that will be displayed */ public static void fillSampleData(ObservableList backingList) { try { client = ApiClientHelper.getApiClient(); + WordApi wordApi = client.buildClient(WordApi.class); WordsApi wordsApi = client.buildClient(WordsApi.class); - WordOfTheDay word = getWordOfTheDay(wordsApi); - List definitions = word.getDefinitions(); - System.out.println(word.getDefinitions()); - if (definitions != null && !definitions.isEmpty()) { - Object definition = definitions.get(0); - if (definition instanceof Map) { - @SuppressWarnings("unchecked") - Map definitionAsMap = (Map) definition; - backingList.add(buildWordRecord(word.getWord(), definitionAsMap)); - } - } + addWordOfTheDay(wordApi, wordsApi, backingList); } catch (IOException e) { System.err.println("Unable to get API key."); } diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index 4d1b950..e85e0f5 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -3,8 +3,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -17,6 +19,8 @@ import edu.mills.cs180a.wordnik.client.api.WordsApi; import edu.mills.cs180a.wordnik.client.model.FrequencySummary; import edu.mills.cs180a.wordnik.client.model.WordOfTheDay; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; class SampleDataTest { @@ -24,11 +28,13 @@ class SampleDataTest { private final WordApi mockWordApi = mock(WordApi.class); @Mock private final WordsApi mockWordsApi = mock(WordsApi.class); - private static final Map PEPPER_DEF = Map.of("text", + private static final Map PEPPER_DEF_MAP = Map.of("text", "A perennial climbing vine (Piper nigrum) native to India, widely cultivated for its long slender spikes of small fruit."); - private static final List DEFS = List.of(PEPPER_DEF); - private static final String PEPPER = "pepper"; - private WordOfTheDay wod = makeWOD(PEPPER, DEFS); + private static final List PEPPER_DEF_LIST = List.of(PEPPER_DEF_MAP); + private static final String PEPPER_STRING = "pepper"; + private WordOfTheDay wod = makeWOD(PEPPER_STRING, PEPPER_DEF_LIST); + private static final FrequencySummary PEPPER_FREQ_SUMMARY = + makeFrequencySummary(List.of(makeFreqMap(2012, 1))); private static final Map FREQS_MAP = Map.of("apple", makeFrequencySummary(List.of(makeFreqMap(2000, 339), makeFreqMap(2001, 464))), "orange", makeFrequencySummary(List.of(makeFreqMap(2000, 774), makeFreqMap(2001, 941)))); @@ -37,6 +43,8 @@ class SampleDataTest { void setup() { when(mockWordApi.getWordFrequency(anyString(), anyString(), anyInt(), anyInt())) .thenAnswer(invocation -> FREQS_MAP.get(invocation.getArgument(0))); + when(mockWordApi.getWordFrequency(eq(PEPPER_STRING), anyString(), anyInt(), anyInt())) + .thenReturn(PEPPER_FREQ_SUMMARY); when(mockWordsApi.getWordOfTheDay()).thenReturn(wod); } @@ -67,17 +75,26 @@ private static WordOfTheDay makeWOD(String word, List defs) { @Test void getWord_True_CorrectWordReturned() { - assertEquals("pepper", SampleData.getWordOfTheDay(mockWordsApi).getWord()); + assertEquals(PEPPER_STRING, SampleData.getWordOfTheDay(mockWordsApi).getWord()); } @SuppressWarnings("unchecked") @Test - void getDefinitions_True_CorrectDefinitionsReturned() { - Map defs = copyMap(PEPPER_DEF); + void getDefinitions_True_CorrectDefinitionsMapReturned() { + Map defs = copyMap(PEPPER_DEF_MAP); assertEquals(defs, (Map) SampleData.getWordOfTheDay(mockWordsApi) .getDefinitions().get(0)); } + @Test + void addWordOfTheDay_True_WordAddedToBackingList() throws IOException { + ObservableList backingList = FXCollections.observableArrayList(); + assertEquals(0, backingList.size()); + SampleData.addWordOfTheDay(mockWordApi, mockWordsApi, backingList); + assertEquals(1, backingList.size()); + assertEquals(PEPPER_STRING, backingList.get(0).getWord()); + } + private Map copyMap(Map originalMap) { Map newMap = new HashMap(); for (Object elt : originalMap.keySet()) { From bf5f2f51f3f43368e519cd5d38c017d23af1aa6d Mon Sep 17 00:00:00 2001 From: BHamrick Date: Thu, 10 Dec 2020 13:33:07 -0800 Subject: [PATCH 06/12] Add test for null backingList in addWordOfTheDay check for null backingList in addWordOfTheDay --- .../java/edu/mills/cs180a/wordui/model/SampleData.java | 3 +++ .../edu/mills/cs180a/wordui/model/SampleDataTest.java | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index 44356a4..90ff203 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -64,6 +64,9 @@ private static WordRecord buildWordRecord(WordApi wordApi, String word, @VisibleForTesting protected static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, ObservableList backingList) { + if (backingList == null) { + throw new IllegalArgumentException("backingList is null"); + } WordOfTheDay word = getWordOfTheDay(wordsApi); List definitions = word.getDefinitions(); if (definitions != null && !definitions.isEmpty()) { diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index e85e0f5..9f2269b 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -1,6 +1,7 @@ package edu.mills.cs180a.wordui.model; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -86,6 +87,13 @@ void getDefinitions_True_CorrectDefinitionsMapReturned() { .getDefinitions().get(0)); } + @Test + void addWordOfTheDay_ExceptionThrown_ObservableListNull() { + assertThrows(IllegalArgumentException.class, () -> { + SampleData.addWordOfTheDay(mockWordApi, mockWordsApi, null); + }); + } + @Test void addWordOfTheDay_True_WordAddedToBackingList() throws IOException { ObservableList backingList = FXCollections.observableArrayList(); From 278cb6600283e384a405490ba01544f7a01b4229 Mon Sep 17 00:00:00 2001 From: BHamrick Date: Mon, 14 Dec 2020 09:38:15 -0800 Subject: [PATCH 07/12] Make suggested changes --- .../mills/cs180a/wordui/model/SampleData.java | 15 +++-- .../cs180a/wordui/model/SampleDataTest.java | 55 +++++++------------ 2 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index 90ff203..400ca33 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -61,8 +61,15 @@ private static WordRecord buildWordRecord(WordApi wordApi, String word, definition.get("text").toString()); } - @VisibleForTesting - protected static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, + /** + * Get the word of the day from Words API, and then place the word record in a JavaFX Observable + * List. + * + * @param wordApi API that returns a word's information + * @param wordsApi API that returns a random word + * @param backingList A list of listeners for changes in objects + */ + public static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, ObservableList backingList) { if (backingList == null) { throw new IllegalArgumentException("backingList is null"); @@ -80,9 +87,9 @@ protected static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, } /** - * Fill backing list with Word of the day and predefined sample words. + * Fill backing list with Word of the Day and predefined sample words. * - * @param backingList a list of word records that will be displayed + * @param backingList a list of Word Records */ public static void fillSampleData(ObservableList backingList) { try { diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index 9f2269b..0dfcc55 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -1,14 +1,12 @@ package edu.mills.cs180a.wordui.model; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; import org.junit.jupiter.api.BeforeEach; @@ -29,12 +27,15 @@ class SampleDataTest { private final WordApi mockWordApi = mock(WordApi.class); @Mock private final WordsApi mockWordsApi = mock(WordsApi.class); - private static final Map PEPPER_DEF_MAP = Map.of("text", - "A perennial climbing vine (Piper nigrum) native to India, widely cultivated for its long slender spikes of small fruit."); - private static final List PEPPER_DEF_LIST = List.of(PEPPER_DEF_MAP); - private static final String PEPPER_STRING = "pepper"; - private WordOfTheDay wod = makeWOD(PEPPER_STRING, PEPPER_DEF_LIST); - private static final FrequencySummary PEPPER_FREQ_SUMMARY = + private static final String SAMPLE_WORD_DEF = + "A perennial climbing vine (Piper nigrum) native to India, widely cultivated for its long slender spikes of small fruit."; + private static final Map SAMPLE_WORD_DEF_MAP = Map.of("text", SAMPLE_WORD_DEF); + private static final List SAMPLE_WORD_DEF_LIST = List.of(SAMPLE_WORD_DEF_MAP); + private static final String SAMPLE_WORD_STRING = "pepper"; + private static final WordOfTheDay WORD_OF_THE_DAY = + makeWOD(SAMPLE_WORD_STRING, SAMPLE_WORD_DEF_LIST); + private static final int SAMPLE_WORD_FREQ = 1; + private static final FrequencySummary SAMPLE_WORD_FREQ_SUMMARY = makeFrequencySummary(List.of(makeFreqMap(2012, 1))); private static final Map FREQS_MAP = Map.of("apple", makeFrequencySummary(List.of(makeFreqMap(2000, 339), makeFreqMap(2001, 464))), "orange", @@ -44,9 +45,9 @@ class SampleDataTest { void setup() { when(mockWordApi.getWordFrequency(anyString(), anyString(), anyInt(), anyInt())) .thenAnswer(invocation -> FREQS_MAP.get(invocation.getArgument(0))); - when(mockWordApi.getWordFrequency(eq(PEPPER_STRING), anyString(), anyInt(), anyInt())) - .thenReturn(PEPPER_FREQ_SUMMARY); - when(mockWordsApi.getWordOfTheDay()).thenReturn(wod); + when(mockWordApi.getWordFrequency(eq(SAMPLE_WORD_STRING), anyString(), anyInt(), anyInt())) + .thenReturn(SAMPLE_WORD_FREQ_SUMMARY); + when(mockWordsApi.getWordOfTheDay()).thenReturn(WORD_OF_THE_DAY); } private static Map makeFreqMap(int year, int count) { @@ -74,24 +75,12 @@ private static WordOfTheDay makeWOD(String word, List defs) { return wod; } - @Test - void getWord_True_CorrectWordReturned() { - assertEquals(PEPPER_STRING, SampleData.getWordOfTheDay(mockWordsApi).getWord()); - } - @SuppressWarnings("unchecked") @Test - void getDefinitions_True_CorrectDefinitionsMapReturned() { - Map defs = copyMap(PEPPER_DEF_MAP); - assertEquals(defs, (Map) SampleData.getWordOfTheDay(mockWordsApi) - .getDefinitions().get(0)); - } - - @Test - void addWordOfTheDay_ExceptionThrown_ObservableListNull() { - assertThrows(IllegalArgumentException.class, () -> { - SampleData.addWordOfTheDay(mockWordApi, mockWordsApi, null); - }); + void getWord_True_CorrectWordReturned() { + assertEquals(SAMPLE_WORD_STRING, SampleData.getWordOfTheDay(mockWordsApi).getWord()); + assertEquals(SAMPLE_WORD_DEF, ((Map) SampleData + .getWordOfTheDay(mockWordsApi).getDefinitions().get(0)).get("text").toString()); } @Test @@ -100,14 +89,8 @@ void addWordOfTheDay_True_WordAddedToBackingList() throws IOException { assertEquals(0, backingList.size()); SampleData.addWordOfTheDay(mockWordApi, mockWordsApi, backingList); assertEquals(1, backingList.size()); - assertEquals(PEPPER_STRING, backingList.get(0).getWord()); - } - - private Map copyMap(Map originalMap) { - Map newMap = new HashMap(); - for (Object elt : originalMap.keySet()) { - newMap.put(elt, originalMap.get(elt)); - } - return newMap; + assertEquals(SAMPLE_WORD_STRING, backingList.get(0).getWord()); + assertEquals(SAMPLE_WORD_DEF, backingList.get(0).getDefinition()); + assertEquals(SAMPLE_WORD_FREQ, backingList.get(0).getFrequency()); } } From 0b911d4152e1da1f6e15ca7042e9d7212e7ad62b Mon Sep 17 00:00:00 2001 From: BHamrick Date: Mon, 14 Dec 2020 09:40:30 -0800 Subject: [PATCH 08/12] Match my conventions --- src/main/java/edu/mills/cs180a/wordui/model/SampleData.java | 2 +- .../java/edu/mills/cs180a/wordui/model/SampleDataTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index 400ca33..e0c8e3a 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -72,7 +72,7 @@ private static WordRecord buildWordRecord(WordApi wordApi, String word, public static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, ObservableList backingList) { if (backingList == null) { - throw new IllegalArgumentException("backingList is null"); + throw new IllegalArgumentException("Backing List is null"); } WordOfTheDay word = getWordOfTheDay(wordsApi); List definitions = word.getDefinitions(); diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index 0dfcc55..1f38c1e 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -32,7 +32,7 @@ class SampleDataTest { private static final Map SAMPLE_WORD_DEF_MAP = Map.of("text", SAMPLE_WORD_DEF); private static final List SAMPLE_WORD_DEF_LIST = List.of(SAMPLE_WORD_DEF_MAP); private static final String SAMPLE_WORD_STRING = "pepper"; - private static final WordOfTheDay WORD_OF_THE_DAY = + private static final WordOfTheDay SAMPLE_WORD_OF_THE_DAY = makeWOD(SAMPLE_WORD_STRING, SAMPLE_WORD_DEF_LIST); private static final int SAMPLE_WORD_FREQ = 1; private static final FrequencySummary SAMPLE_WORD_FREQ_SUMMARY = @@ -47,7 +47,7 @@ void setup() { .thenAnswer(invocation -> FREQS_MAP.get(invocation.getArgument(0))); when(mockWordApi.getWordFrequency(eq(SAMPLE_WORD_STRING), anyString(), anyInt(), anyInt())) .thenReturn(SAMPLE_WORD_FREQ_SUMMARY); - when(mockWordsApi.getWordOfTheDay()).thenReturn(WORD_OF_THE_DAY); + when(mockWordsApi.getWordOfTheDay()).thenReturn(SAMPLE_WORD_OF_THE_DAY); } private static Map makeFreqMap(int year, int count) { From eb4bc0daf53d1a068c2b74f1dd0c7a70585b84a4 Mon Sep 17 00:00:00 2001 From: BHamrick Date: Thu, 17 Dec 2020 13:48:09 -0800 Subject: [PATCH 09/12] Fix syntax errors to match conventions and fix tests --- src/main/java/edu/mills/cs180a/wordui/model/SampleData.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index e0c8e3a..bbe6798 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -62,7 +62,7 @@ private static WordRecord buildWordRecord(WordApi wordApi, String word, } /** - * Get the word of the day from Words API, and then place the word record in a JavaFX Observable + * Get the Word of the Day from Words API, and then place the Word Record in a JavaFX Observable * List. * * @param wordApi API that returns a word's information From 17abef5f9747232015fae18473eb6b34d1357ff3 Mon Sep 17 00:00:00 2001 From: BHamrick Date: Thu, 17 Dec 2020 14:39:46 -0800 Subject: [PATCH 10/12] Remove unnecessary line in gitignore file --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6bcc1dc..e97612b 100644 --- a/.gitignore +++ b/.gitignore @@ -61,5 +61,4 @@ local.properties /target/ api-key.txt -#git .log *.log From 053f2d33ec0be4cefd311d7959dce7ab710725ff Mon Sep 17 00:00:00 2001 From: BHamrick Date: Mon, 21 Dec 2020 22:03:32 -0800 Subject: [PATCH 11/12] Revision to match requests --- .../edu/mills/cs180a/wordui/model/SampleData.java | 8 ++++---- .../mills/cs180a/wordui/model/SampleDataTest.java | 14 ++++++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index bbe6798..df1d8ae 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -65,9 +65,9 @@ private static WordRecord buildWordRecord(WordApi wordApi, String word, * Get the Word of the Day from Words API, and then place the Word Record in a JavaFX Observable * List. * - * @param wordApi API that returns a word's information - * @param wordsApi API that returns a random word - * @param backingList A list of listeners for changes in objects + * @param wordApi returns a word's information + * @param wordsApi returns a random word + * @param backingList a list */ public static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, ObservableList backingList) { @@ -89,7 +89,7 @@ public static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, /** * Fill backing list with Word of the Day and predefined sample words. * - * @param backingList a list of Word Records + * @param backingList a list */ public static void fillSampleData(ObservableList backingList) { try { diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index 1f38c1e..5ea223a 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -35,8 +35,9 @@ class SampleDataTest { private static final WordOfTheDay SAMPLE_WORD_OF_THE_DAY = makeWOD(SAMPLE_WORD_STRING, SAMPLE_WORD_DEF_LIST); private static final int SAMPLE_WORD_FREQ = 1; + private static final int SAMPLE_WORD_YEAR = 2012; private static final FrequencySummary SAMPLE_WORD_FREQ_SUMMARY = - makeFrequencySummary(List.of(makeFreqMap(2012, 1))); + makeFrequencySummary(List.of(makeFreqMap(SAMPLE_WORD_YEAR, SAMPLE_WORD_FREQ))); private static final Map FREQS_MAP = Map.of("apple", makeFrequencySummary(List.of(makeFreqMap(2000, 339), makeFreqMap(2001, 464))), "orange", makeFrequencySummary(List.of(makeFreqMap(2000, 774), makeFreqMap(2001, 941)))); @@ -78,9 +79,14 @@ private static WordOfTheDay makeWOD(String word, List defs) { @SuppressWarnings("unchecked") @Test void getWord_True_CorrectWordReturned() { - assertEquals(SAMPLE_WORD_STRING, SampleData.getWordOfTheDay(mockWordsApi).getWord()); - assertEquals(SAMPLE_WORD_DEF, ((Map) SampleData - .getWordOfTheDay(mockWordsApi).getDefinitions().get(0)).get("text").toString()); + WordOfTheDay word = SampleData.getWordOfTheDay(mockWordsApi); + assertEquals(SAMPLE_WORD_STRING, word.getWord()); + assertEquals(1, word.getDefinitions().size()); + assertEquals(SAMPLE_WORD_DEF, + ((Map) word.getDefinitions().get(0)).get("text").toString()); + int freqNumOfWord = + SampleData.getFrequencyByYear(mockWordApi, word.getWord(), SAMPLE_WORD_YEAR); + assertEquals(SAMPLE_WORD_FREQ, freqNumOfWord); } @Test From 609360e1b8f90218d2585ce26212c84a468b73d9 Mon Sep 17 00:00:00 2001 From: BHamrick Date: Thu, 24 Dec 2020 16:34:19 -0800 Subject: [PATCH 12/12] Rename outdated test add CSV for sample string remove static method calls --- .../mills/cs180a/wordui/model/SampleData.java | 4 ++-- .../cs180a/wordui/model/SampleDataTest.java | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java index df1d8ae..50bdb4d 100644 --- a/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java +++ b/src/main/java/edu/mills/cs180a/wordui/model/SampleData.java @@ -65,8 +65,8 @@ private static WordRecord buildWordRecord(WordApi wordApi, String word, * Get the Word of the Day from Words API, and then place the Word Record in a JavaFX Observable * List. * - * @param wordApi returns a word's information - * @param wordsApi returns a random word + * @param wordApi api that returns a word's information + * @param wordsApi api that returns a random word * @param backingList a list */ public static void addWordOfTheDay(WordApi wordApi, WordsApi wordsApi, diff --git a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java index 5ea223a..78f3258 100644 --- a/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java +++ b/src/test/java/edu/mills/cs180a/wordui/model/SampleDataTest.java @@ -36,6 +36,8 @@ class SampleDataTest { makeWOD(SAMPLE_WORD_STRING, SAMPLE_WORD_DEF_LIST); private static final int SAMPLE_WORD_FREQ = 1; private static final int SAMPLE_WORD_YEAR = 2012; + private static final String SAMPLE_WORD_CSV = SAMPLE_WORD_STRING + "," + SAMPLE_WORD_YEAR + + "," + SAMPLE_WORD_FREQ; private static final FrequencySummary SAMPLE_WORD_FREQ_SUMMARY = makeFrequencySummary(List.of(makeFreqMap(SAMPLE_WORD_YEAR, SAMPLE_WORD_FREQ))); private static final Map FREQS_MAP = Map.of("apple", @@ -64,7 +66,7 @@ private static FrequencySummary makeFrequencySummary(List freqs) { @ParameterizedTest @CsvSource({"apple,2000,339", "apple,2001,464", "apple,2020,0", "orange,2000,774", - "orange,2001,941", "orange,2050,0"}) + "orange,2001,941", "orange,2050,0", SAMPLE_WORD_CSV}) void testGetFrequencyFromSummary(String word, int year, int count) { assertEquals(count, SampleData.getFrequencyByYear(mockWordApi, word, year)); } @@ -78,15 +80,12 @@ private static WordOfTheDay makeWOD(String word, List defs) { @SuppressWarnings("unchecked") @Test - void getWord_True_CorrectWordReturned() { + void getWordOfTheDay_True_CorrectWordReturned() { WordOfTheDay word = SampleData.getWordOfTheDay(mockWordsApi); assertEquals(SAMPLE_WORD_STRING, word.getWord()); assertEquals(1, word.getDefinitions().size()); assertEquals(SAMPLE_WORD_DEF, ((Map) word.getDefinitions().get(0)).get("text").toString()); - int freqNumOfWord = - SampleData.getFrequencyByYear(mockWordApi, word.getWord(), SAMPLE_WORD_YEAR); - assertEquals(SAMPLE_WORD_FREQ, freqNumOfWord); } @Test @@ -95,8 +94,9 @@ void addWordOfTheDay_True_WordAddedToBackingList() throws IOException { assertEquals(0, backingList.size()); SampleData.addWordOfTheDay(mockWordApi, mockWordsApi, backingList); assertEquals(1, backingList.size()); - assertEquals(SAMPLE_WORD_STRING, backingList.get(0).getWord()); - assertEquals(SAMPLE_WORD_DEF, backingList.get(0).getDefinition()); - assertEquals(SAMPLE_WORD_FREQ, backingList.get(0).getFrequency()); + WordRecord wordRecordFromList = backingList.get(0); + assertEquals(SAMPLE_WORD_STRING, wordRecordFromList.getWord()); + assertEquals(SAMPLE_WORD_DEF, wordRecordFromList.getDefinition()); + assertEquals(SAMPLE_WORD_FREQ, wordRecordFromList.getFrequency()); } }