1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.student.enrollment.class2.courseoffering.service.impl;
18
19 import org.junit.Test;
20 import org.kuali.student.enrollment.courseoffering.dto.ActivityOfferingInfo;
21 import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 import static org.junit.Assert.assertEquals;
27
28
29
30
31
32
33 public class TestCourseOfferingCodeGeneratorImpl {
34
35 @Test
36 public void testGenerator(){
37 CourseOfferingCodeGeneratorImpl impl = new CourseOfferingCodeGeneratorImpl();
38 String code;
39 code = impl.generateActivityOfferingCode(new ArrayList<ActivityOfferingInfo>());
40 assertEquals("A",code);
41
42 List<ActivityOfferingInfo> aos = new ArrayList<ActivityOfferingInfo>();
43 for(char c='A';c<='Z';c++){
44 ActivityOfferingInfo a = new ActivityOfferingInfo();
45 a.setActivityCode(String.valueOf(c));
46
47 aos.add(a);
48 }
49 code = impl.generateActivityOfferingCode(aos);
50 assertEquals("AA",code);
51
52 aos.remove(3);
53
54 code = impl.generateActivityOfferingCode(aos);
55 assertEquals("D",code);
56
57 }
58
59 @Test
60 public void testGetNextCode(){
61 CourseOfferingCodeGeneratorImpl impl = new CourseOfferingCodeGeneratorImpl();
62 assertEquals("A",impl.getNextCode(""));
63 assertEquals("E",impl.getNextCode("D"));
64 assertEquals("AA",impl.getNextCode("Z"));
65 assertEquals("AF",impl.getNextCode("AE"));
66 assertEquals("BA",impl.getNextCode("AZ"));
67 assertEquals("BF",impl.getNextCode("BE"));
68 assertEquals("ZB",impl.getNextCode("ZA"));
69 assertEquals("AAA",impl.getNextCode("ZZ"));
70 assertEquals("AAF",impl.getNextCode("AAE"));
71 assertEquals("ABA",impl.getNextCode("AAZ"));
72 assertEquals("ABG",impl.getNextCode("ABF"));
73 assertEquals("AAAA",impl.getNextCode("ZZZ"));
74 assertEquals("AAEB",impl.getNextCode("AAEA"));
75 assertEquals("AAZB",impl.getNextCode("AAZA"));
76 assertEquals("ABAA",impl.getNextCode("AAZZ"));
77 assertEquals("AZAC",impl.getNextCode("AZAB"));
78 assertEquals("ZZZD",impl.getNextCode("ZZZC"));
79 assertEquals("AAAAA",impl.getNextCode("ZZZZ"));
80 }
81
82 @Test
83 public void testGenerateCourseOfferingInternalCode(){
84 CourseOfferingCodeGeneratorImpl impl = new CourseOfferingCodeGeneratorImpl();
85 String code;
86 code = impl.generateCourseOfferingInternalCode(new ArrayList<CourseOfferingInfo>());
87 assertEquals("A",code);
88
89 List<CourseOfferingInfo> cos = new ArrayList<CourseOfferingInfo>();
90 for(char c='A';c<='Z';c++){
91 CourseOfferingInfo a = new CourseOfferingInfo();
92 a.setCourseNumberSuffix(String.valueOf(c));
93
94 cos.add(a);
95 }
96 code = impl.generateCourseOfferingInternalCode(cos);
97 assertEquals("AA",code);
98
99 cos.remove(3);
100
101 code = impl.generateCourseOfferingInternalCode(cos);
102 assertEquals("D",code);
103 }
104 }