use of app.abhijit.iter.models.Student in project bunk by abhijitparida.
the class ResponseParserTest method parse_EmptyAttendanceJson_ReturnsStudentWithEmptySubjectList.
@Test
public void parse_EmptyAttendanceJson_ReturnsStudentWithEmptySubjectList() {
ResponseParser responseParser = new ResponseParser();
Student student = responseParser.parse("{\"name\":\"name\",\"status\":\"success\"}", "");
assertEquals(0, student.subjects.size());
}
use of app.abhijit.iter.models.Student in project bunk by abhijitparida.
the class ResponseParserTest method parse_InvalidAttendanceJson_ReturnsStudentWithEmptySubjectList.
@Test
public void parse_InvalidAttendanceJson_ReturnsStudentWithEmptySubjectList() {
ResponseParser responseParser = new ResponseParser();
Student student = responseParser.parse("{\"name\":\"name\",\"status\":\"success\"}", "bad json");
assertEquals(0, student.subjects.size());
}
use of app.abhijit.iter.models.Student in project bunk by abhijitparida.
the class ResponseParserTest method parse_ValidAttendanceJson_ParsesCorrectly.
@Test
public void parse_ValidAttendanceJson_ParsesCorrectly() {
ResponseParser responseParser = new ResponseParser();
Student student = responseParser.parse("{\"name\":\"name\",\"status\":\"success\"}", "{\"griddata\":[{\"Latt\":\"10 / 10\",\"Patt\":\"Not Applicable\",\"subject\":\"Subject I\",\"subjectcode\":\"SUB001\"},{\"Latt\":\"Not Applicable\",\"Patt\":\"20 / 20\",\"subject\":\"Subject II\",\"subjectcode\":\"SUB002\"}]}");
HashMap<String, Subject> subjects = student.subjects;
assertEquals(2, subjects.size());
assertEquals("Subject I", subjects.get("SUB001").name);
assertEquals("SUB001", subjects.get("SUB001").code);
assertEquals(10, subjects.get("SUB001").theoryPresent);
assertEquals(10, subjects.get("SUB001").theoryTotal);
assertEquals(0, subjects.get("SUB001").labPresent);
assertEquals(0, subjects.get("SUB001").labTotal);
assertEquals("Subject II", subjects.get("SUB002").name);
assertEquals("SUB002", subjects.get("SUB002").code);
assertEquals(0, subjects.get("SUB002").theoryPresent);
assertEquals(0, subjects.get("SUB002").theoryTotal);
assertEquals(20, subjects.get("SUB002").labPresent);
assertEquals(20, subjects.get("SUB002").labTotal);
}
use of app.abhijit.iter.models.Student in project bunk by abhijitparida.
the class LoginActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mContext = this;
mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
mCache = new Cache(mContext);
mIterApi = new IterApi(mContext);
mUsernameInput = findViewById(R.id.username);
mPasswordInput = findViewById(R.id.password);
mPasswordVisilibity = findViewById(R.id.password_visibility);
mLoginButton = findViewById(R.id.login);
setupToolbar();
setupLoginButton();
final ArrayList<Student> students = mCache.getStudents();
final ArrayList<String> usernames = new ArrayList<>();
for (Student student : students) {
usernames.add(student.username);
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(mContext, android.R.layout.simple_dropdown_item_1line, usernames);
mUsernameInput.setAdapter(adapter);
mUsernameInput.setThreshold(1);
mUsernameInput.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
int index = usernames.indexOf(mUsernameInput.getText().toString());
mPasswordInput.setText(students.get(index).password);
}
});
Student selectedStudent = mCache.getStudent(mSharedPreferences.getString("pref_student", null));
if (selectedStudent != null) {
mUsernameInput.setText(selectedStudent.username);
mPasswordInput.setText(selectedStudent.password);
mLoginButton.performClick();
}
}
use of app.abhijit.iter.models.Student in project bunk by abhijitparida.
the class ResponseParser method processLogin.
private Student processLogin(String loginJson) {
JsonObject login;
try {
login = this.jsonParser.parse(loginJson).getAsJsonObject();
} catch (Exception e) {
throw new InvalidResponseException();
}
if (!login.has("status") || !login.has("name")) {
throw new InvalidResponseException();
}
if (!login.get("status").getAsString().equals("success")) {
throw new InvalidCredentialsException();
}
Student student = new Student();
student.name = WordUtils.capitalizeFully(login.get("name").getAsString());
return student;
}
Aggregations