1 package org.kuali.student.lum.statement.config.context;
2
3 import java.util.ArrayList;
4 import java.util.List;
5 import java.util.Map;
6
7 import org.junit.Assert;
8 import org.junit.Before;
9 import org.junit.Test;
10 import org.kuali.student.common.exceptions.OperationFailedException;
11 import org.kuali.student.core.statement.dto.ReqCompFieldInfo;
12 import org.kuali.student.core.statement.dto.ReqComponentInfo;
13 import org.kuali.student.lum.statement.typekey.ReqComponentFieldTypes;
14
15 public class GpaContextImplTest {
16 private GpaContextImpl gpaContext = new GpaContextImpl();
17 private ReqComponentInfo reqComponent1;
18 private ReqComponentInfo reqComponent2;
19
20 private void setupReqComponent1() {
21 reqComponent1 = new ReqComponentInfo();
22 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
23 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
24 reqCompField1.setType(ReqComponentFieldTypes.GPA_KEY.getId());
25 reqCompField1.setValue("2.75");
26 reqCompFieldList.add(reqCompField1);
27 reqComponent1.setReqCompFields(reqCompFieldList);
28 }
29
30 private void setupReqComponent2() {
31 reqComponent2 = new ReqComponentInfo();
32 List<ReqCompFieldInfo> reqCompFieldList = new ArrayList<ReqCompFieldInfo>();
33 ReqCompFieldInfo reqCompField1 = new ReqCompFieldInfo();
34 reqCompField1.setType(ReqComponentFieldTypes.GPA_KEY.getId());
35 reqCompField1.setValue(null);
36 reqCompFieldList.add(reqCompField1);
37 reqComponent2.setReqCompFields(reqCompFieldList);
38 }
39
40 @Before
41 public void beforeMethod() {
42 setupReqComponent1();
43 setupReqComponent2();
44 }
45
46 @Test
47 public void testCreateContextMap() throws OperationFailedException {
48 Map<String, Object> contextMap = gpaContext.createContextMap(reqComponent1);
49 Double gpa = (Double) contextMap.get(GpaContextImpl.GPA_TOKEN);
50 Assert.assertEquals(2.75d, gpa.doubleValue(), 0d);
51 }
52
53 @Test
54 public void testCreateContextMap_NullGpa() throws OperationFailedException {
55 Map<String, Object> contextMap = gpaContext.createContextMap(reqComponent2);
56 Double gpa = (Double) contextMap.get(GpaContextImpl.GPA_TOKEN);
57 Assert.assertEquals(null, gpa);
58 }
59 }