This repository has been archived by the owner on Aug 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from schul-cloud/37-increase-test-coverage
37 increase test coverage of models
- Loading branch information
Showing
16 changed files
with
874 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
104 changes: 104 additions & 0 deletions
104
app/src/test/java/org/schulcloud/mobile/SettingsPresenterTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package org.schulcloud.mobile; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
import org.schulcloud.mobile.data.DataManager; | ||
import org.schulcloud.mobile.data.model.Device; | ||
import org.schulcloud.mobile.data.model.Event; | ||
import org.schulcloud.mobile.test.common.TestDataFactory; | ||
import org.schulcloud.mobile.ui.settings.SettingsMvpView; | ||
import org.schulcloud.mobile.ui.settings.SettingsPresenter; | ||
import org.schulcloud.mobile.util.RxSchedulersOverrideRule; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import rx.Observable; | ||
|
||
import static org.mockito.Matchers.anyListOf; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.powermock.api.mockito.PowerMockito.doReturn; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class SettingsPresenterTest { | ||
|
||
@Rule | ||
public final RxSchedulersOverrideRule mOverrideSchedulersRule = new RxSchedulersOverrideRule(); | ||
@Mock | ||
SettingsMvpView mMockSettingsMvpView; | ||
@Mock | ||
DataManager mMockDataManager; | ||
private SettingsPresenter mSettingsPresenter; | ||
|
||
@Before | ||
public void setUp() { | ||
mSettingsPresenter = new SettingsPresenter(mMockDataManager); | ||
mSettingsPresenter.attachView(mMockSettingsMvpView); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
mSettingsPresenter.detachView(); | ||
} | ||
|
||
@Test | ||
public void loadEventsReturnsEvents() { | ||
List<Event> events = TestDataFactory.makeListEvents(10); | ||
doReturn(Observable.just(events)) | ||
.when(mMockDataManager) | ||
.getEvents(); | ||
|
||
mSettingsPresenter.loadEvents(); | ||
verify(mMockSettingsMvpView).connectToCalendar(events); | ||
verify(mMockSettingsMvpView, never()).showEventsEmpty(); | ||
} | ||
|
||
@Test | ||
public void loadEventsReturnsEmptyList() { | ||
doReturn(Observable.just(Collections.emptyList())) | ||
.when(mMockDataManager) | ||
.getEvents(); | ||
|
||
mSettingsPresenter.loadEvents(); | ||
verify(mMockSettingsMvpView).showEventsEmpty(); | ||
verify(mMockSettingsMvpView, never()).connectToCalendar(anyListOf(Event.class)); | ||
} | ||
|
||
@Test | ||
public void loadEventsFails() { | ||
doReturn(Observable.error(new RuntimeException())) | ||
.when(mMockDataManager) | ||
.getEvents(); | ||
|
||
mSettingsPresenter.loadEvents(); | ||
verify(mMockSettingsMvpView, never()).showEventsEmpty(); | ||
verify(mMockSettingsMvpView, never()).connectToCalendar(anyListOf(Event.class)); | ||
} | ||
|
||
@Test | ||
public void loadDevices() { | ||
List<Device> devices = TestDataFactory.makeListDevices(10); | ||
doReturn(Observable.just(devices)) | ||
.when(mMockDataManager) | ||
.getDevices(); | ||
|
||
mSettingsPresenter.loadDevices(); | ||
verify(mMockSettingsMvpView).showDevices(devices); | ||
} | ||
|
||
@Test | ||
public void loadDevicesFails() { | ||
doReturn(Observable.error(new RuntimeException())) | ||
.when(mMockDataManager) | ||
.getDevices(); | ||
|
||
mSettingsPresenter.loadDevices(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
app/src/test/java/org/schulcloud/mobile/data/model/AccessTokenTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package org.schulcloud.mobile.data.model; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static junit.framework.Assert.assertEquals; | ||
import static junit.framework.Assert.assertNotNull; | ||
|
||
public class AccessTokenTest { | ||
private static final String ACCESTOKEN = "OHNOACCESS"; | ||
|
||
private AccessToken accessToken; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
accessToken = createAccesToken(); | ||
} | ||
|
||
public static AccessToken createAccesToken() { | ||
AccessToken accessToken = new AccessToken(); | ||
accessToken.accessToken = ACCESTOKEN; | ||
|
||
return accessToken; | ||
} | ||
|
||
@Test | ||
public void getAccessToken() throws Exception { | ||
assertEquals(accessToken.getAccessToken(), ACCESTOKEN); | ||
} | ||
|
||
@Test | ||
public void setAccessToken() throws Exception { | ||
accessToken.setAccessToken(ACCESTOKEN); | ||
assertNotNull(accessToken.getAccessToken()); | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
app/src/test/java/org/schulcloud/mobile/data/model/CurrentUserTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
package org.schulcloud.mobile.data.model; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class CurrentUserTest { | ||
private static final String _ID = "key"; | ||
private static final String FIRSTNAME = "Ernst"; | ||
private static final String LASTNAME = "Haft"; | ||
private static final String EMAIL = "[email protected]"; | ||
private static final String SCHOOLID = "123214123"; | ||
private static final String DISPLAYNAME = "Ernst Haft"; | ||
|
||
private CurrentUser user; | ||
|
||
@Before | ||
public void setUp() { | ||
user = createNewUser(); | ||
} | ||
|
||
public static CurrentUser createNewUser() { | ||
CurrentUser user = new CurrentUser(); | ||
user.set_id(_ID); | ||
user.setDisplayName(DISPLAYNAME); | ||
user.setSchoolId(SCHOOLID); | ||
user.setLastName(LASTNAME); | ||
user.setFirstName(FIRSTNAME); | ||
user.setEmail(EMAIL); | ||
|
||
return user; | ||
} | ||
|
||
@Test | ||
public void get_id() throws Exception { | ||
assertEquals(user.get_id(), _ID); | ||
} | ||
|
||
@Test | ||
public void set_id() throws Exception { | ||
user.set_id(_ID); | ||
assertNotNull(user.get_id()); | ||
} | ||
|
||
@Test | ||
public void getFirstName() throws Exception { | ||
assertEquals(user.getFirstName(), FIRSTNAME); | ||
} | ||
|
||
@Test | ||
public void setFirstName() throws Exception { | ||
user.setFirstName(FIRSTNAME); | ||
assertNotNull(user.getFirstName()); | ||
} | ||
|
||
@Test | ||
public void getLastName() throws Exception { | ||
assertEquals(user.getLastName(), LASTNAME); | ||
} | ||
|
||
@Test | ||
public void setLastName() throws Exception { | ||
user.setLastName(LASTNAME); | ||
assertNotNull(user.getLastName()); | ||
} | ||
|
||
@Test | ||
public void getEmail() throws Exception { | ||
assertEquals(user.getEmail(), EMAIL); | ||
} | ||
|
||
@Test | ||
public void setEmail() throws Exception { | ||
user.setEmail(EMAIL); | ||
assertNotNull(user.getEmail()); | ||
} | ||
|
||
@Test | ||
public void getSchoolId() throws Exception { | ||
assertEquals(user.getSchoolId(), SCHOOLID); | ||
} | ||
|
||
@Test | ||
public void setSchoolId() throws Exception { | ||
user.setSchoolId(SCHOOLID); | ||
assertNotNull(user.getSchoolId()); | ||
} | ||
|
||
@Test | ||
public void getDisplayName() throws Exception { | ||
assertEquals(user.getDisplayName(), DISPLAYNAME); | ||
} | ||
|
||
@Test | ||
public void setDisplayName() throws Exception { | ||
user.setDisplayName(DISPLAYNAME); | ||
assertNotNull(user.getDisplayName()); | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
app/src/test/java/org/schulcloud/mobile/data/model/DeviceTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package org.schulcloud.mobile.data.model; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class DeviceTest { | ||
private static final String _ID = "_ID"; | ||
private static final String TOKEN = "TOKEN"; | ||
private static final String TYPE = "MOBILE"; | ||
private static final String SERVICE = "SERVICE"; | ||
private static final String NAME = "NAME"; | ||
private static final String OS = "MAGIC"; | ||
private static final String STATE = "UNKNOWN"; | ||
private static final String UPDATEDAT = "YESTERDAY"; | ||
private static final String CREATEDAT = "NOW"; | ||
private static final String ACTIVE = "TRUE"; | ||
|
||
private Device device; | ||
|
||
@Before | ||
public void setUp() { | ||
device = createNewDevice(); | ||
} | ||
|
||
@Test | ||
public void testGetProperties() { | ||
assertEquals(device.name, NAME); | ||
assertEquals(device._id, _ID); | ||
assertEquals(device.token, TOKEN); | ||
assertEquals(device.type, TYPE); | ||
assertEquals(device.service, SERVICE); | ||
assertEquals(device.OS, OS); | ||
assertEquals(device.state, STATE); | ||
assertEquals(device.updatedAt, UPDATEDAT); | ||
assertEquals(device.createdAt, CREATEDAT); | ||
assertEquals(device.active, ACTIVE); | ||
} | ||
|
||
public static Device createNewDevice() { | ||
Device device = new Device(); | ||
device.name = NAME; | ||
device._id = _ID; | ||
device.token = TOKEN; | ||
device.type = TYPE; | ||
device.service = SERVICE; | ||
device.OS = OS; | ||
device.state = STATE; | ||
device.createdAt = CREATEDAT; | ||
device.updatedAt = UPDATEDAT; | ||
device.active = ACTIVE; | ||
|
||
return device; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
app/src/test/java/org/schulcloud/mobile/data/model/DirectoryTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.schulcloud.mobile.data.model; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class DirectoryTest { | ||
private static final String NAME = "NAME"; | ||
|
||
private Directory directory; | ||
|
||
@Before | ||
public void setUp() { | ||
directory = createNewDirectory(); | ||
} | ||
|
||
@Test | ||
public void testGetProperties() { | ||
assertEquals(directory.name, NAME); | ||
|
||
} | ||
|
||
public static Directory createNewDirectory() { | ||
Directory directory = new Directory(); | ||
directory.name = NAME; | ||
|
||
return directory; | ||
} | ||
} |
Oops, something went wrong.