Commit 22035701 by Paktalin

Initial commit

parents
Showing with 1518 additions and 0 deletions
<component name="ProjectDictionaryState">
<dictionary name="Paktalin">
<words>
<w>paktalin</w>
</words>
</dictionary>
</component>
\ No newline at end of file
<component name="libraryTable">
<library name="Arquillian JUnit:Release" type="repository">
<properties maven-id="org.jboss.arquillian.junit:arquillian-junit-container:RELEASE" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/junit/arquillian-junit-container/1.4.1.Final/arquillian-junit-container-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/junit/arquillian-junit-core/1.4.1.Final/arquillian-junit-core-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/test/arquillian-test-api/1.4.1.Final/arquillian-test-api-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/core/arquillian-core-api/1.4.1.Final/arquillian-core-api-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/test/arquillian-test-spi/1.4.1.Final/arquillian-test-spi-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/core/arquillian-core-spi/1.4.1.Final/arquillian-core-spi-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/container/arquillian-container-test-api/1.4.1.Final/arquillian-container-test-api-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/shrinkwrap/shrinkwrap-api/1.2.6/shrinkwrap-api-1.2.6.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/shrinkwrap/descriptors/shrinkwrap-descriptors-api-base/2.0.0/shrinkwrap-descriptors-api-base-2.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/container/arquillian-container-test-spi/1.4.1.Final/arquillian-container-test-spi-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/container/arquillian-container-spi/1.4.1.Final/arquillian-container-spi-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/core/arquillian-core-impl-base/1.4.1.Final/arquillian-core-impl-base-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/test/arquillian-test-impl-base/1.4.1.Final/arquillian-test-impl-base-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/container/arquillian-container-impl-base/1.4.1.Final/arquillian-container-impl-base-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/config/arquillian-config-api/1.4.1.Final/arquillian-config-api-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/config/arquillian-config-impl-base/1.4.1.Final/arquillian-config-impl-base-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/config/arquillian-config-spi/1.4.1.Final/arquillian-config-spi-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/shrinkwrap/descriptors/shrinkwrap-descriptors-spi/2.0.0/shrinkwrap-descriptors-spi-2.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/arquillian/container/arquillian-container-test-impl-base/1.4.1.Final/arquillian-container-test-impl-base-1.4.1.Final.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/shrinkwrap/shrinkwrap-impl-base/1.2.6/shrinkwrap-impl-base-1.2.6.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jboss/shrinkwrap/shrinkwrap-spi/1.2.6/shrinkwrap-spi-1.2.6.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_10" default="true" project-jdk-name="10" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/AgileJava.iml" filepath="$PROJECT_DIR$/AgileJava.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/com/paktalin/agilejava/main" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/com/paktalin/agilejava/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit5.0">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.0.0/junit-jupiter-api-5.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.0.0/apiguardian-api-1.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.0.0/opentest4j-1.0.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.0.0/junit-platform-commons-1.0.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="Arquillian JUnit:Release" level="project" />
<orderEntry type="module-library" scope="TEST">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
\ No newline at end of file
package com.paktalin.agilejava;
/**
* Created by Paktalin on 18/05/2018.
*/
class BasicGradingStrategy {
public int getGradePointsFor(Student.Grade grade) {
return grade.getPoints();
}
}
package com.paktalin.agilejava;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Created by Paktalin on 18/05/2018.
*/
class CourseReport {
private List<CourseSession> sessions = new ArrayList<>();
void add(CourseSession session) {
sessions.add(session);
Collections.sort(sessions);
}
String text() {
StringBuilder buffer = new StringBuilder();
for (CourseSession session : sessions) {
buffer.append(session.getDepartment());
buffer.append(" ");
buffer.append(session.getNumber());
buffer.append(RosterReporter.NEW_LINE);
}
return buffer.toString();
}
}
package com.paktalin.agilejava;
import java.util.Date;
/**
* Created by Paktalin on 16/05/2018.
*/
public class CourseSession extends Session {
private static int count = 0;
private CourseSession(String department, String number, Date startDate) {
super(department, number, startDate);
}
static CourseSession create(String department, String number, Date startDate) {
incrementCount();
return new CourseSession(department, number, startDate);
}
static int getCount() {
return CourseSession.count;
}
static void resetCount() {
CourseSession.count = 0;
}
private static void incrementCount() {
CourseSession.count++;
}
@Override
protected int getSessionLength() {
return 16;
}
}
package com.paktalin.agilejava;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
/**
* Created by Paktalin on 17/05/2018.
*/
class DateUtil {
//That's how static initialization block works
static {
long now = System.currentTimeMillis();
Date then = new Date(now + 86400000);
}
private DateUtil() {}
static Date createDate(int year, int month, int date) {
GregorianCalendar calendar = new GregorianCalendar();
calendar.clear();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month - 1);
calendar.set(Calendar.DAY_OF_MONTH, date);
return calendar.getTime();
}
}
package com.paktalin.agilejava;
/**
* Created by Paktalin on 18/05/2018.
*/
class HonorsGradingStrategy extends BasicGradingStrategy {
@Override
public int getGradePointsFor(Student.Grade grade) {
int points = super.getGradePointsFor(grade);
if (points != 0)
points++;
return points;
}
}
package com.paktalin.agilejava;
/**
* Created by Paktalin on 02/06/2018.
*/
class Performance {
private int[] tests;
double average() {
if (tests.length == 0) return 0;
double total = 0;
for (int score : tests)
total += score;
return total / tests.length;
}
void setNumberOfTests(int numberOfTests) {
tests = new int[numberOfTests];
}
void set(int index, int score) {
tests[index] = score;
}
void setScores(int... scores) {
if (tests == null)
tests = new int[scores.length];
System.arraycopy(scores, 0, tests, 0, tests.length);
}
int get(int index) {
return tests[index];
}
}
package com.paktalin.agilejava;
import java.util.EnumMap;
import java.util.Map;
/**
* Created by Paktalin on 27/05/2018.
*/
class ReportCard {
static final String A_MESSAGE = "Excellent!";
static final String B_MESSAGE = "Very good";
static final String C_MESSAGE = "Hmmm...";
static final String D_MESSAGE = "You're not trying";
static final String F_MESSAGE = "Loser";
private Map<Student.Grade, String> messages = null;
String getMessage(Student.Grade grade) {
return getMessages().get(grade);
}
private Map<Student.Grade, String> getMessages() {
if (messages == null)
loadMessages();
return messages;
}
private void loadMessages() {
messages = new EnumMap<>(Student.Grade.class);
messages.put(Student.Grade.A, A_MESSAGE);
messages.put(Student.Grade.B, B_MESSAGE);
messages.put(Student.Grade.C, C_MESSAGE);
messages.put(Student.Grade.D, D_MESSAGE);
messages.put(Student.Grade.F, F_MESSAGE);
}
}
package com.paktalin.agilejava;
/**
* Created by Paktalin on 17/05/2018.
*/
class RosterReporter {
static final String NEW_LINE = System.getProperty("line.separator");
static String ROSTER_REPORT_HEADER = "com.paktalin.agilejava.main.Student" + NEW_LINE + "_____" + NEW_LINE;
static String ROSTER_REPORT_FOOTER = NEW_LINE + "# students = ";
private CourseSession session;
private StringBuilder buffer;
RosterReporter(CourseSession session) {
this.session = session;
}
String getReport() {
buffer = new StringBuilder();
writeHeader();
writeBody();
writeFooter();
return buffer.toString();
}
private void writeHeader() {
buffer.append(ROSTER_REPORT_HEADER);
}
private void writeBody() {
for (Student student : session.getAllStudents()) {
buffer.append(student.getName());
buffer.append(NEW_LINE);
}
}
private void writeFooter() {
buffer.append(ROSTER_REPORT_FOOTER).append(session.getAllStudents().size()).append(NEW_LINE);
}
}
package com.paktalin.agilejava;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
/**
* Created by Paktalin on 30/05/2018.
*/
public abstract class Session implements Comparable<Session>, Iterable<Student>{
private String department;
private String number;
private List<Student> students = new ArrayList<>();
private Date startDate;
private int numberOfCredits;
Session(String department, String number, Date startDate) {
this.department = department;
this.number = number;
this.startDate = startDate;
}
@Override
public int compareTo(Session that) {
int compare = this.getDepartment().compareTo(that.getDepartment());
if (compare != 0)
return compare;
return this.getNumber().compareTo(that.getNumber());
}
@Override
public Iterator<Student> iterator() {
return students.iterator();
}
void setNumberOfCredits(int numberOfCredits) {
this.numberOfCredits = numberOfCredits;
}
void enroll(Student student) {
students.add(student);
student.addCredits(numberOfCredits);
}
double getAverageGpaForPartTimeStudents() {
double total = 0;
int count = 0;
for (Student student : getAllStudents()) {
if (student.isFullTime())
continue;
count++;
total += student.getGpa();
}
if (count == 0) return 0.0;
return total / count;
}
protected abstract int getSessionLength();
Date getEndDate() {
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(getStartDate());
calendar.add(Calendar.DAY_OF_YEAR, getNumberOfDaysInSession());
return calendar.getTime();
}
private int getNumberOfDaysInSession() {
final int daysInWeek = 7;
final int daysFromFridayToMonday = 3;
return getSessionLength() * daysInWeek - daysFromFridayToMonday;
}
List<Student> getAllStudents() {
return students;
}
Date getStartDate() {
return startDate;
}
int getNumberOfStudents() {
return students.size();
}
String getDepartment() {
return department;
}
String getNumber() {
return number;
}
Student get(int index) {
return students.get(index);
}
}
package com.paktalin.agilejava;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Paktalin on 15/05/2018.
*/
public class Student {
private String name;
private String firstName = "", middleName = "", lastName;
private int credits;
static final int CREDITS_REQUIRED_FOR_FULL_TIME = 12;
static final String IN_STATE = "CO";
private String state = "";
private List<Grade> grades = new ArrayList<>();
private BasicGradingStrategy gradingStrategy = new BasicGradingStrategy();
private List<Integer> charges = new ArrayList<>();
enum Grade {
A(4), B(3), C(2), D(1), F(0);
private int points;
Grade(int points) {
this.points = points;
}
int getPoints() {
return points;
}
}
public Student(String fullName) {
setNames(fullName);
credits = 0;
}
void addCredits(int credits) {
this.credits += credits;
}
void addGrade(Grade grade) {
grades.add(grade);
}
void addCharge(int charge) {
charges.add(charge);
}
int totalCharges() {
int total = 0;
for (Integer charge : charges)
total += charge;
return total;
}
private void setNames(String fullName) {
this.name = fullName;
String[] nameSplit = fullName.split(" ");
switch (nameSplit.length){
case 1:
lastName = nameSplit[0];
break;
case 2:
firstName = nameSplit[0];
lastName = nameSplit[1];
break;
default:
firstName = nameSplit[0];
middleName = nameSplit[1];
lastName = nameSplit[2];
break;
}
}
void setState(String state) {
this.state = state.toUpperCase();
}
void setGradingStrategy(HonorsGradingStrategy gradingStrategy) {
this.gradingStrategy = gradingStrategy;
}
boolean isFullTime() {
return credits >= Student.CREDITS_REQUIRED_FOR_FULL_TIME;
}
boolean isInState() {
return state.equals(Student.IN_STATE);
}
double getGpa() {
if (grades.isEmpty())
return 0.0;
double total = 0.0;
for (Grade grade : grades)
total += gradingStrategy.getGradePointsFor(grade);
return total/grades.size();
}
int getCredits() {
return credits;
}
public String getName() {
return name;
}
String getFirstName() {
return firstName;
}
String getLastName() {
return lastName;
}
String getMiddleName() {
return middleName;
}
}
package com.paktalin.agilejava;
import java.util.Date;
/**
* Created by Paktalin on 28/05/2018.
*/
public class SummerCourseSession extends Session {
private static int count = 0;
private SummerCourseSession(String department, String number, Date startDate) {
super(department, number, startDate);
}
static SummerCourseSession create(String department, String number, Date startDate) {
incrementCount();
return new SummerCourseSession(department, number, startDate);
}
static int getCount() {
return SummerCourseSession.count;
}
static void resetCount() {
SummerCourseSession.count = 0;
}
private static void incrementCount() {
SummerCourseSession.count++;
}
@Override
protected int getSessionLength() {
return 8;
}
}
\ No newline at end of file
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 28/05/2018.
*/
class BasicGradingStrategyTest {
@Test
void testGetGradePoints() {
BasicGradingStrategy strategy = new BasicGradingStrategy();
assertEquals(4, strategy.getGradePointsFor(Student.Grade.A));
assertEquals(3, strategy.getGradePointsFor(Student.Grade.B));
assertEquals(2, strategy.getGradePointsFor(Student.Grade.C));
assertEquals(1, strategy.getGradePointsFor(Student.Grade.D));
assertEquals(0, strategy.getGradePointsFor(Student.Grade.F));
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static com.paktalin.agilejava.RosterReporter.NEW_LINE;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 18/05/2018.
*/
class CourseReportTest {
@Test
void testReport() {
final Date date = new Date();
CourseReport report = new CourseReport();
report.add(CourseSession.create("ENGL", "101", date));
report.add(CourseSession.create("CZEC", "200", date));
report.add(CourseSession.create("ITAL", "410", date));
report.add(CourseSession.create("CZEC", "220", date));
report.add(CourseSession.create("ITAL", "330", date));
assertEquals(
"CZEC 200" + NEW_LINE +
"CZEC 220" + NEW_LINE +
"ENGL 101" + NEW_LINE +
"ITAL 330" + NEW_LINE +
"ITAL 410" + NEW_LINE,
report.text());
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 16/05/2018.
*/
public class CourseSessionTest extends SessionTest {
@Override
protected CourseSession createSession(String department, String number, Date startDate) {
return CourseSession.create(department, number, startDate);
}
@Test
void testCount() {
CourseSession.resetCount();
createSession(" ", "", new Date());
assertEquals(1, CourseSession.getCount());
createSession(" ", "", new Date());
assertEquals(2, CourseSession.getCount());
}
@Override
protected Date getExpectedEndDate() {
return DateUtil.createDate(2003, 4, 25);
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 17/05/2018.
*/
class DateUtilTest {
@Test
void testCreateDate() {
Date date = DateUtil.createDate(2000, 1, 1);
Calendar calendar = new GregorianCalendar();
calendar.setTime(date);
assertEquals(2000, calendar.get(Calendar.YEAR));
assertEquals(Calendar.JANUARY, calendar.get(Calendar.MONTH));
assertEquals(1, calendar.get(Calendar.DAY_OF_MONTH));
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 28/05/2018.
*/
class HonorsGradingStrategyTest {
@Test
void testGetGradePoints() {
HonorsGradingStrategy strategy = new HonorsGradingStrategy();
assertEquals(5, strategy.getGradePointsFor(Student.Grade.A));
assertEquals(4, strategy.getGradePointsFor(Student.Grade.B));
assertEquals(3, strategy.getGradePointsFor(Student.Grade.C));
assertEquals(2, strategy.getGradePointsFor(Student.Grade.D));
assertEquals(0, strategy.getGradePointsFor(Student.Grade.F));
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 02/06/2018.
*/
class PerformanceTest {
static private final double TOLERANCE = 0.005;
private Performance performance;
@BeforeEach
void init() throws Exception {
performance = new Performance();
}
@Test
void testAverage() {
performance.setNumberOfTests(4);
performance.set(0, 98);
performance.set(1, 92);
performance.set(2, 81);
performance.set(3, 72);
assertEquals(92, performance.get(1));
assertEquals(85.75, performance.average(), TOLERANCE);
}
@Test
void testVarargs() {
performance.setScores(80, 90, 100);
assertEquals(80, performance.get(0));
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 27/05/2018.
*/
class ReportCardTest {
@Test
void testMessage() {
ReportCard card = new ReportCard();
assertEquals(ReportCard.A_MESSAGE, card.getMessage(Student.Grade.A));
assertEquals(ReportCard.B_MESSAGE, card.getMessage(Student.Grade.B));
assertEquals(ReportCard.C_MESSAGE, card.getMessage(Student.Grade.C));
assertEquals(ReportCard.D_MESSAGE, card.getMessage(Student.Grade.D));
assertEquals(ReportCard.F_MESSAGE, card.getMessage(Student.Grade.F));
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import static com.paktalin.agilejava.RosterReporter.NEW_LINE;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 17/05/2018.
*/
class RosterReporterTest {
@Test
void testRosterReport() {
CourseSession session = CourseSession.create("ENGL", "101",
DateUtil.createDate(2003, 1, 6));
session.enroll(new Student("A"));
session.enroll(new Student("B"));
String rosterReport = new RosterReporter(session).getReport();
System.out.println(rosterReport);
assertEquals(
RosterReporter.ROSTER_REPORT_HEADER +
"A" + NEW_LINE +
"B" + NEW_LINE +
RosterReporter.ROSTER_REPORT_FOOTER + "2" +
NEW_LINE, rosterReport);
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Created by Paktalin on 30/05/2018.
*/
abstract public class SessionTest {
private Session session;
private Date startDate;
private static final int CREDITS = 3;
@BeforeEach
void init() {
startDate = DateUtil.createDate(2003, 1, 6);
session = createSession("ENGL", "101", startDate);
session.setNumberOfCredits(CREDITS);
}
protected abstract Session createSession(String department, String number, Date startDate);
protected abstract Date getExpectedEndDate();
@Test
void testCreate() {
assertEquals("ENGL", session.getDepartment());
assertEquals("101", session.getNumber());
assertEquals(0, session.getNumberOfStudents());
assertEquals(startDate, session.getStartDate());
}
@Test
void testEnrollStudents() {
Student student1 = new Student("Cain DiVoe");
session.enroll(student1);
assertEquals(CREDITS, student1.getCredits());
assertEquals(student1, session.get(0));
assertEquals(1, session.getNumberOfStudents());
Student student2 = new Student("Coralee DeVaughn");
session.enroll(student2);
assertEquals(CREDITS, student1.getCredits());
assertEquals(student2, session.get(1));
assertEquals(2, session.getNumberOfStudents());
}
@Test
void testComparable() {
Date date = new Date();
Session sessionA = createSession("CMSC", "101", date);
Session sessionB = createSession("ENGL", "101", date);
assertTrue(sessionA.compareTo(sessionB) < 0);
assertTrue(sessionB.compareTo(sessionA) > 0);
Session sessionC = createSession("CMSC", "101", date);
assertEquals(0, sessionA.compareTo(sessionC));
Session sessionD = createSession("CMSC", "210", date);
assertTrue(sessionC.compareTo(sessionD) < 0);
assertTrue(sessionD.compareTo(sessionC) > 0);
}
@Test
void testCourseDates() {
Date startDate = DateUtil.createDate(2003, 1, 6);
Session session = createSession("ENGL", "200", startDate);
assertEquals(getExpectedEndDate(), session.getEndDate());
}
@Test
void testAverageGpaForPartTimeStudents() {
session.enroll(createFullTimeStudent());
assertEquals(1, session.getNumberOfStudents());
createPartTimer("1", Student.Grade.A);
assertEquals(2, session.getNumberOfStudents());
createPartTimer("2", Student.Grade.D);
assertEquals(3, session.getNumberOfStudents());
assertEquals(2.5, session.getAverageGpaForPartTimeStudents(), 0.05);
}
@Test
void testIterate() {
enrollStudents(session);
List<Student> results = new ArrayList<>();
for (Student student : session)
results.add(student);
assertEquals(session.getAllStudents(), results);
}
private void createPartTimer(String name, Student.Grade grade) {
Student partTimer = new Student(name);
partTimer.addGrade(grade);
session.enroll(partTimer);
assertFalse(partTimer.isFullTime());
assertEquals(grade.getPoints(), partTimer.getGpa(), 0.05);
}
private Student createFullTimeStudent() {
Student student = new Student("a");
student.addCredits(Student.CREDITS_REQUIRED_FOR_FULL_TIME);
return student;
}
private void enrollStudents(Session session) {
session.enroll(new Student("1"));
session.enroll(new Student("2"));
session.enroll(new Student("3"));
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Starting with TDD here.
* Test for Student class
*/
class StudentTest {
@Test
void testCreate() {
Student student = new Student("Jane Doe");
verifyNamesCorrect(student, "Jane Doe", "Jane", "Doe", "");
student = new Student("Blow");
verifyNamesCorrect(student, "Blow", "", "Blow", "");
student = new Student("Raymond Douglas Davies");
verifyNamesCorrect(student, "Raymond Douglas Davies",
"Raymond", "Davies", "Douglas");
}
@Test
void testStudentStatus() {
Student student = new Student("a");
assertEquals(0, student.getCredits());
assertFalse(student.isFullTime());
student.addCredits(3);
assertEquals(3, student.getCredits());
assertFalse(student.isFullTime());
student.addCredits(4);
assertEquals(7, student.getCredits());
assertFalse(student.isFullTime());
student.addCredits(5);
assertEquals(Student.CREDITS_REQUIRED_FOR_FULL_TIME, student.getCredits());
assertTrue(student.isFullTime(), "Not enough credits for FullTime status");
}
@Test
void testInState() {
Student student = new Student("a");
assertFalse(student.isInState());
student.setState(Student.IN_STATE);
assertTrue(student.isInState());
student.setState("MD");
assertFalse(student.isInState());
}
@Test
void testCalculateGpa() {
Student student = new Student("a");
assertGpa(student, 0.0);
student.addGrade(Student.Grade.A);
assertGpa(student, 4.0);
student.addGrade(Student.Grade.B);
assertGpa(student, 3.5);
student.addGrade(Student.Grade.C);
assertGpa(student, 3.0);
student.addGrade(Student.Grade.D);
assertGpa(student, 2.5);
student.addGrade(Student.Grade.F);
assertGpa(student, 2.0);
}
@Test
void testCalculateHonorsStudentGpa() {
Student student = createHonorsStudent();
assertGpa(student, 0.0);
student.addGrade(Student.Grade.A);
assertGpa(student, 5.0);
student.addGrade(Student.Grade.B);
assertGpa(student, 4.5);
student.addGrade(Student.Grade.C);
assertGpa(student, 4.0);
student.addGrade(Student.Grade.D);
assertGpa(student, 3.5);
student.addGrade(Student.Grade.F);
assertGpa(student, 2.8);
}
@Test
void testCharges() {
Student student = new Student("a");
student.addCharge(500);
student.addCharge(200);
student.addCharge(399);
assertEquals(1099, student.totalCharges());
}
private void assertGpa(Student student, double expectedGpa) {
final double GRADE_TOLERANCE = 0.05;
assertEquals(expectedGpa, student.getGpa(), GRADE_TOLERANCE);
}
private Student createHonorsStudent() {
Student student = new Student("a");
student.setGradingStrategy(new HonorsGradingStrategy());
return student;
}
private void verifyNamesCorrect(
Student student, String name, String firstName, String lastName, String middleName) {
assertEquals(name, student.getName());
assertEquals(firstName, student.getFirstName());
assertEquals(lastName, student.getLastName());
assertEquals(middleName, student.getMiddleName());
}
}
package com.paktalin.agilejava;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Created by Paktalin on 28/05/2018.
*/
public class SummerCourseSessionTest extends SessionTest {
@Override
protected SummerCourseSession createSession(String department, String number, Date startDate) {
return SummerCourseSession.create(department, number, startDate);
}
@Test
void testCount() {
SummerCourseSession.resetCount();
createSession(" ", "", new Date());
assertEquals(1, SummerCourseSession.getCount());
createSession(" ", "", new Date());
assertEquals(2, SummerCourseSession.getCount());
}
@Override
protected Date getExpectedEndDate() {
return DateUtil.createDate(2003, 2, 28);
}
}
package com.paktalin.agilejava.language_tests;
import com.paktalin.agilejava.Student;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Created by Paktalin on 17/05/2018.
*/
class LanguageTests {
@Test
void testCharValue() {
char capitalA = 'A';
assertEquals(65, capitalA);
assertEquals('\u0041', capitalA);
assertEquals('\101', capitalA);
}
@Test
void testConcatenation() {
assertEquals("abcd", "ab".concat("cd"));
assertEquals("abcd", "ab" + "cd");
assertEquals("abcd", "ab" + "c" + "d");
}
@Test
void testIncrement() {
int i = 5;
assertEquals(12, ++i * 2);
assertEquals(6, i);
i = 5;
assertEquals(10, i++ * 2);
assertEquals(6, i);
}
@Test
void testCollectionsSort() {
List<String> list = new ArrayList<>();
list.add("Heller");
list.add("Kafka");
list.add("Camus");
list.add("Boyle");
java.util.Collections.sort(list);
assertEquals("Boyle", list.get(0));
assertEquals("Camus", list.get(1));
assertEquals("Heller", list.get(2));
assertEquals("Kafka", list.get(3));
}
@Test
void testCompareTo() {
assertTrue("A".compareTo("B") < 0);
assertEquals(0, "A".compareTo("A"));
assertTrue("B".compareTo("A") > 0);
}
enum Score {fieldGoal, touchdown, extraPoint, twoPointConversion, safety}
@Test
void testSwitchResults() {
int totalPoints = 0;
Score score = Score.touchdown;
switch (score) {
case fieldGoal:
totalPoints += 3;
break;
case touchdown:
totalPoints += 6;
break;
case extraPoint:
totalPoints += 1;
break;
case twoPointConversion:
case safety:
totalPoints += 2;
break;
}
assertEquals(6, totalPoints);
}
@Test
//Old way casting
void testCasting() {
List students = new ArrayList();
students.add(new Student("a"));
students.add(new Student("b"));
List names = new ArrayList();
Iterator it = students.iterator();
while (it.hasNext()) {
Student student = (Student)it.next();
names.add(student.getName());
}
assertEquals("a", names.get(0));
assertEquals("b", names.get(1));
}
@Test
//Old way splitting
void testTokenizer() {
String name = "Jane Doe";
assertEquals("Jane", split(name).get(0));
assertEquals("Doe", split(name).get(1));
}
private List<String> split(String string) {
List<String> results = new ArrayList<>();
StringTokenizer tokenizer = new StringTokenizer(string, " ");
while (tokenizer.hasMoreTokens())
results.add(tokenizer.nextToken());
return results;
}
}
package com.paktalin.agilejava.language_tests;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Created by Paktalin on 01/06/2018.
*/
class LoopTest {
private String[] array;
@BeforeEach
void init() throws Exception {
array = new String[]{"apple", "a", "banana", "k", "grapefruit", "pineapple"};
}
@Test
void testMultipleConditionsLoop() {
int i, count;
for (i = 0, count = 0; i < array.length; i++)
if (array[i].length() > 1)
count++;
assertEquals(4, count);
}
@Test
void testPalindrome() {
assertFalse(isPalindrome("abcd"));
assertTrue(isPalindrome("abba"));
assertTrue(isPalindrome(""));
assertFalse(isPalindrome("abbaa"));
}
@Test
void testFibonacci() {
assertEquals(0, fib(0));
assertEquals(1, fib(1));
assertEquals(1, fib(2));
assertEquals(2, fib(3));
assertEquals(3, fib(4));
assertEquals(5, fib(5));
}
@Test
void testEndTrim() {
assertEquals("", endTrim(""));
assertEquals(" x", endTrim(" x "));
assertEquals("y", endTrim("y"));
assertEquals("xaxa", endTrim("xaxa"));
assertEquals("", endTrim(" "));
assertEquals("xxx", endTrim("xxx "));
}
@Test
void testLabeledBreak() {
List<List<String>> table = new ArrayList<>();
List<String> row1 = new ArrayList<>();
row1.add("5");
row1.add("2");
List<String> row2 = new ArrayList<>();
row2.add("3");
row2.add("4");
table.add(row1);
table.add(row2);
assertTrue(found(table, "3"));
}
private boolean isPalindrome(String string){
int limit = string.length() / 2;
for
(int forward = 0, backward = string.length() - 1;
forward < limit;
forward++, backward--)
if (string.charAt(forward) != string.charAt(backward))
return false;
return true;
}
private int fib(int x) {
if (x == 0)
return 0;
if (x == 1)
return 1;
return fib(x - 1) + fib(x - 2);
}
private String endTrim(String source) {
int i = source.length() - 1;
while (i >= 0) {
if (source.charAt(i) != ' ')
break;
i--;
}
return source.substring(0, i + 1);
}
private boolean found(List<List<String>> table, String target) {
boolean found = false;
search:
for (List<String> row : table)
for (String value : row) {
if (value.equals(target)) {
found = true;
break search;
}
}
return found;
}
}
\ No newline at end of file
package com.paktalin.agilejava.language_tests;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* Created by Paktalin on 28/05/2018.
*/
class SuperClassTest {
@Test
void testConstructorCalls() {
SuperClass superClass = new SubClass("parm");
assertTrue(superClass.constructorWasCalled);
}
class SuperClass {
boolean constructorWasCalled = false;
SuperClass(String parm) {
constructorWasCalled = true;
}
}
class SubClass extends SuperClass {
SubClass(String parm) {
super(parm);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment