-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleTest.java
85 lines (69 loc) · 1.81 KB
/
ModuleTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package com.B5015845.CSC8002.Coursework.Testing;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.Scanner;
import org.junit.Before;
import org.junit.Test;
import com.B5015845.CSC8002.Coursework.Module;
/**
* This test class is ModuleTest, designed to test the ability to store and retrieve Modules.
* @author Arianna Esposito
*/
public class ModuleTest {
Module m;
@Before
public void setUp() throws FileNotFoundException
{
m = Module.getInstance("CSC5001");
}
/*
* Tests an illegal argument is passed through parameter
*/
@Test(expected=IllegalArgumentException.class)
public void setUpIllegalArgumentException() throws FileNotFoundException, IllegalArgumentException
{
m = Module.getInstance("NonExistentModuleCode");
}
@Test
public void testReadModuleList() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("Modules"));
inFile.close();
}
/*
* Tests the file not found exception
*/
@Test(expected=FileNotFoundException.class)
public void testReadModuleListFileNotFound() throws FileNotFoundException
{
Scanner inFile = new Scanner(new FileReader("Test"));
inFile.close();
}
@Test
public void testGetModuleCode()
{
assertEquals("CSC5001", m.getModuleCode());
}
@Test
public void testGetName()
{
assertEquals("How to: Java",m.getName());
}
@Test
public void testGetCredits()
{
assertEquals(20,m.getCredits());
}
@Test
public void testGetInstance()
{
assertTrue(m instanceof Module);
}
@Test
public void testGetModules() throws FileNotFoundException
{
assertTrue(Module.getListedModules().containsKey(m.getModuleCode()));
}
}