-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from Divyeshhhh/tutotest
write tests for TutorialModel
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/test/java/com/github/creme332/tests/model/TutorialModelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.github.creme332.tests.model; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.junit.Test; | ||
import com.github.creme332.model.TutorialModel; | ||
|
||
public class TutorialModelTest { | ||
|
||
@Test | ||
public void testTitle() { | ||
String title = "Java Programming Basics"; | ||
TutorialModel tutorial = new TutorialModel(title); | ||
assertEquals(title, tutorial.getTitle()); | ||
} | ||
|
||
@Test | ||
public void testKeywordsFromTitle() { | ||
String title = "Java Programming Basics"; | ||
TutorialModel tutorial = new TutorialModel(title); | ||
Set<String> expectedKeywords = new HashSet<>(Arrays.asList("java", "programming", "basics")); | ||
Set<String> actualKeywords = new HashSet<>(Arrays.asList(tutorial.getKeywords())); | ||
assertEquals(expectedKeywords, actualKeywords); | ||
} | ||
|
||
@Test | ||
public void testAddValidKeyword() { | ||
TutorialModel tutorial = new TutorialModel("Test Title"); | ||
tutorial.addKeyword("keyword"); | ||
Set<String> expectedKeywords = new HashSet<>(Arrays.asList("test", "title", "keyword")); | ||
Set<String> actualKeywords = new HashSet<>(Arrays.asList(tutorial.getKeywords())); | ||
assertEquals(expectedKeywords, actualKeywords); | ||
} | ||
|
||
@Test | ||
public void testAddInvalidKeyword() { | ||
TutorialModel tutorial = new TutorialModel("Test Title"); | ||
tutorial.addKeyword("kw"); | ||
Set<String> expectedKeywords = new HashSet<>(Arrays.asList("test", "title")); | ||
Set<String> actualKeywords = new HashSet<>(Arrays.asList(tutorial.getKeywords())); | ||
assertEquals(expectedKeywords, actualKeywords); | ||
} | ||
|
||
@Test | ||
public void testCaseInsensitivityOfKeywords() { | ||
TutorialModel tutorial = new TutorialModel("Test Title"); | ||
tutorial.addKeyword("Keyword"); | ||
tutorial.addKeyword("KEYWORD"); | ||
tutorial.addKeyword("keyword"); | ||
Set<String> expectedKeywords = new HashSet<>(Arrays.asList("test", "title", "keyword")); | ||
Set<String> actualKeywords = new HashSet<>(Arrays.asList(tutorial.getKeywords())); | ||
assertEquals(expectedKeywords, actualKeywords); | ||
} | ||
} |