Last active
September 30, 2016 02:17
-
-
Save usbportnoy/7a7a45f8058c1330ed94244ad673706d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.dkary.portj.danichat; | |
import com.dkary.portj.danichat.fragments.profile.OnlineStatus; | |
import com.dkary.portj.danichat.models.Profile; | |
import org.junit.Test; | |
import static org.junit.Assert.assertEquals; | |
import java.util.Calendar; | |
public class ProfileOnlineStatusTest { | |
@Test | |
public void online() throws Exception { | |
Profile profile = new Profile(); | |
//sets instance to right now | |
Calendar calendar = Calendar.getInstance(); | |
//get time of right now and set users online status with it | |
profile.setLastOnline(calendar.getTime()); | |
//create and configure | |
OnlineStatus onlineStatus = new OnlineStatus(); | |
onlineStatus.setOnlineThresholdHrs(1); | |
onlineStatus.setRecentOnlineThresholdDays(7); | |
OnlineStatus.States status = onlineStatus.getStatus( | |
profile.getLastOnline(), | |
Calendar.getInstance() | |
); | |
assertEquals(OnlineStatus.States.Online, status); | |
} | |
@Test | |
public void this_week() throws Exception { | |
Profile profile = new Profile(); | |
//sets instance to right now | |
Calendar calendar = Calendar.getInstance(); | |
// 6 days is less than a week | |
calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - 6); | |
//get time of right now and set users online status with it | |
profile.setLastOnline(calendar.getTime()); | |
//create and configure | |
OnlineStatus onlineStatus = new OnlineStatus(); | |
onlineStatus.setOnlineThresholdHrs(1); | |
onlineStatus.setRecentOnlineThresholdDays(7); | |
OnlineStatus.States status = onlineStatus.getStatus( | |
profile.getLastOnline(), | |
Calendar.getInstance() | |
); | |
assertEquals(OnlineStatus.States.Recent, status); | |
} | |
@Test | |
public void this_month() throws Exception { | |
Profile profile = new Profile(); | |
Calendar calendar = Calendar.getInstance(); | |
calendar.set(Calendar.WEEK_OF_YEAR, calendar.get(Calendar.WEEK_OF_YEAR) - 3); | |
profile.setLastOnline(calendar.getTime()); | |
OnlineStatus onlineStatus = new OnlineStatus(); | |
onlineStatus.setOnlineThresholdHrs(1); | |
onlineStatus.setRecentOnlineThresholdDays(7); | |
onlineStatus.setDistantOnlineThresholdWeeks(4); | |
OnlineStatus.States status = onlineStatus.getStatus( | |
profile.getLastOnline(), | |
Calendar.getInstance() | |
); | |
assertEquals(OnlineStatus.States.Distant, status); | |
} | |
@Test | |
public void not_recently() throws Exception { | |
Profile profile = new Profile(); | |
Calendar calendar = Calendar.getInstance(); | |
calendar.set(Calendar.WEEK_OF_YEAR, calendar.get(Calendar.WEEK_OF_YEAR) - 5); | |
profile.setLastOnline(calendar.getTime()); | |
OnlineStatus onlineStatus = new OnlineStatus(); | |
onlineStatus.setOnlineThresholdHrs(1); | |
onlineStatus.setRecentOnlineThresholdDays(7); | |
onlineStatus.setDistantOnlineThresholdWeeks(4); | |
OnlineStatus.States status = onlineStatus.getStatus( | |
profile.getLastOnline(), | |
Calendar.getInstance() | |
); | |
assertEquals(OnlineStatus.States.Offline, status); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment