This repository has been archived by the owner on Apr 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
95 changed files
with
2,041 additions
and
395 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
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
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
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
147 changes: 147 additions & 0 deletions
147
matrix-sdk/src/androidTest/java/org/matrix/androidsdk/data/room/RoomAvatarResolverTest.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,147 @@ | ||
/* | ||
* Copyright 2018 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.androidsdk.data.room; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.FixMethodOrder; | ||
import org.junit.Test; | ||
import org.junit.runners.MethodSorters; | ||
import org.matrix.androidsdk.data.Room; | ||
|
||
@FixMethodOrder(MethodSorters.JVM) | ||
public class RoomAvatarResolverTest { | ||
|
||
private RoomTestHelper mRoomTestHelper = new RoomTestHelper(); | ||
|
||
@Test | ||
public void RoomAvatar_getAvatar_noLL_avatar() { | ||
RoomAvatar_getAvatar_avatar(false); | ||
} | ||
|
||
@Test | ||
public void RoomAvatar_getAvatar_LL_avatar() { | ||
RoomAvatar_getAvatar_avatar(true); | ||
} | ||
|
||
private void RoomAvatar_getAvatar_avatar(boolean withLazyLoading) { | ||
Context context = InstrumentationRegistry.getContext(); | ||
|
||
// It does not depend on the number of users | ||
for (int i = 0; i < 10; i++) { | ||
Room room = mRoomTestHelper.createRoom(context, withLazyLoading, i, false); | ||
|
||
room.getState().avatar_url = "mxc://avatar_url"; | ||
Assert.assertEquals("mxc://avatar_url", room.getAvatarUrl()); | ||
} | ||
} | ||
|
||
@Test | ||
public void RoomAvatar_getAvatar_noLL_noAvatar() { | ||
RoomAvatar_getAvatar_noAvatar(false); | ||
} | ||
|
||
@Test | ||
public void RoomAvatar_getAvatar_LL_noAvatar() { | ||
RoomAvatar_getAvatar_noAvatar(true); | ||
} | ||
|
||
private void RoomAvatar_getAvatar_noAvatar(boolean withLazyLoading) { | ||
Context context = InstrumentationRegistry.getContext(); | ||
|
||
Room room; | ||
|
||
// Only me in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 1, false); | ||
Assert.assertNull(room.getAvatarUrl()); | ||
|
||
// I have an avatar | ||
room.getMember(mRoomTestHelper.getMyUserId()).avatarUrl = "mxc://my_avatar_url"; | ||
Assert.assertEquals("mxc://my_avatar_url", room.getAvatarUrl()); | ||
|
||
// One other user in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 2, false); | ||
Assert.assertNull(room.getAvatarUrl()); | ||
|
||
// I have an avatar | ||
room.getMember(mRoomTestHelper.getMyUserId()).avatarUrl = "mxc://my_avatar_url"; | ||
Assert.assertNull(room.getAvatarUrl()); | ||
|
||
// Other user has an avatar | ||
room.getMember(mRoomTestHelper.getUserId(2)).avatarUrl = "mxc://other_user_avatar_url"; | ||
Assert.assertEquals("mxc://other_user_avatar_url", room.getAvatarUrl()); | ||
|
||
// 2 other users in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 3, false); | ||
|
||
// I have an avatar | ||
room.getMember(mRoomTestHelper.getMyUserId()).avatarUrl = "mxc://my_avatar_url"; | ||
// Other user has an avatar | ||
room.getMember(mRoomTestHelper.getUserId(2)).avatarUrl = "mxc://other_user_avatar_url"; | ||
|
||
Assert.assertNull(room.getAvatarUrl()); | ||
} | ||
|
||
@Test | ||
public void RoomAvatar_getAvatar_noLL_invitation() { | ||
RoomAvatar_getAvatar_invitation(false); | ||
} | ||
|
||
@Test | ||
public void RoomAvatar_getAvatar_LL_invitation() { | ||
RoomAvatar_getAvatar_invitation(true); | ||
} | ||
|
||
private void RoomAvatar_getAvatar_invitation(boolean withLazyLoading) { | ||
Context context = InstrumentationRegistry.getContext(); | ||
|
||
Room room; | ||
|
||
// Only me in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 1, true); | ||
Assert.assertNull(room.getAvatarUrl()); | ||
|
||
// I have an avatar | ||
room.getMember(mRoomTestHelper.getMyUserId()).avatarUrl = "mxc://my_avatar_url"; | ||
Assert.assertEquals("mxc://my_avatar_url", room.getAvatarUrl()); | ||
|
||
// One other user in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 2, true); | ||
Assert.assertNull(room.getAvatarUrl()); | ||
|
||
// I have an avatar | ||
room.getMember(mRoomTestHelper.getMyUserId()).avatarUrl = "mxc://my_avatar_url"; | ||
Assert.assertNull(room.getAvatarUrl()); | ||
|
||
// Inviter has an avatar | ||
room.getMember(mRoomTestHelper.getUserId(2)).avatarUrl = "mxc://other_user_avatar_url"; | ||
Assert.assertEquals("mxc://other_user_avatar_url", room.getAvatarUrl()); | ||
|
||
// 2 other users in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 3, true); | ||
|
||
// I have an avatar | ||
room.getMember(mRoomTestHelper.getMyUserId()).avatarUrl = "mxc://my_avatar_url"; | ||
// Other user has an avatar | ||
room.getMember(mRoomTestHelper.getUserId(2)).avatarUrl = "mxc://other_user_avatar_url"; | ||
|
||
Assert.assertEquals("mxc://other_user_avatar_url", room.getAvatarUrl()); | ||
} | ||
} |
157 changes: 157 additions & 0 deletions
157
...sdk/src/androidTest/java/org/matrix/androidsdk/data/room/RoomDisplayNameResolverTest.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,157 @@ | ||
/* | ||
* Copyright 2018 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.androidsdk.data.room; | ||
|
||
import android.content.Context; | ||
import android.support.test.InstrumentationRegistry; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.junit.FixMethodOrder; | ||
import org.junit.Test; | ||
import org.junit.runners.MethodSorters; | ||
import org.matrix.androidsdk.data.Room; | ||
|
||
import java.util.ArrayList; | ||
|
||
@FixMethodOrder(MethodSorters.JVM) | ||
public class RoomDisplayNameResolverTest { | ||
|
||
private RoomTestHelper mRoomTestHelper = new RoomTestHelper(); | ||
|
||
@Test | ||
public void RoomName_getRoomDisplayName_noLL_emptyRoom() { | ||
RoomName_getRoomDisplayName_emptyRoom(false); | ||
} | ||
|
||
@Test | ||
public void RoomName_getRoomDisplayName_LL_emptyRoom() { | ||
RoomName_getRoomDisplayName_emptyRoom(true); | ||
} | ||
|
||
private void RoomName_getRoomDisplayName_emptyRoom(boolean withLazyLoading) { | ||
Context context = InstrumentationRegistry.getContext(); | ||
Room room = mRoomTestHelper.createRoom(context, withLazyLoading, 0, false); | ||
|
||
Assert.assertEquals("Empty room", room.getRoomDisplayName(context)); | ||
} | ||
|
||
@Test | ||
public void RoomName_getRoomDisplayName_noLL_roomName() { | ||
RoomName_getRoomDisplayName_roomName(false); | ||
} | ||
|
||
@Test | ||
public void RoomName_getRoomDisplayName_LL_roomName() { | ||
RoomName_getRoomDisplayName_roomName(true); | ||
} | ||
|
||
private void RoomName_getRoomDisplayName_roomName(boolean withLazyLoading) { | ||
Context context = InstrumentationRegistry.getContext(); | ||
|
||
// It does not depend on the number of users | ||
for (int i = 0; i < 10; i++) { | ||
Room room = mRoomTestHelper.createRoom(context, withLazyLoading, i, false); | ||
|
||
room.getState().aliases = new ArrayList<>(); | ||
room.getState().aliases.add("Alias"); | ||
Assert.assertEquals("Alias", room.getRoomDisplayName(context)); | ||
|
||
// Canonical alias get priority over alias | ||
room.getState().setCanonicalAlias("Canonical"); | ||
Assert.assertEquals("Canonical", room.getRoomDisplayName(context)); | ||
|
||
// Room name get priority over alias and canonical alias | ||
room.getState().name = "Room Name"; | ||
Assert.assertEquals("Room Name", room.getRoomDisplayName(context)); | ||
} | ||
} | ||
|
||
@Test | ||
public void RoomName_getRoomDisplayName_noLL_user() { | ||
RoomName_getRoomDisplayName_user(false); | ||
} | ||
|
||
@Test | ||
public void RoomName_getRoomDisplayName_LL_user() { | ||
RoomName_getRoomDisplayName_user(true); | ||
} | ||
|
||
private void RoomName_getRoomDisplayName_user(boolean withLazyLoading) { | ||
Context context = InstrumentationRegistry.getContext(); | ||
|
||
Room room; | ||
|
||
// Only me in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 1, false); | ||
Assert.assertEquals("Empty room", room.getRoomDisplayName(context)); | ||
|
||
// One other user in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 2, false); | ||
Assert.assertEquals("UserName_2", room.getRoomDisplayName(context)); | ||
|
||
// 2 other users in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 3, false); | ||
Assert.assertEquals("UserName_2 and UserName_3", room.getRoomDisplayName(context)); | ||
|
||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 4, false); | ||
Assert.assertEquals("UserName_2 and 3 others", room.getRoomDisplayName(context)); | ||
|
||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 5, false); | ||
Assert.assertEquals("UserName_2 and 4 others", room.getRoomDisplayName(context)); | ||
|
||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 10, false); | ||
Assert.assertEquals("UserName_2 and 9 others", room.getRoomDisplayName(context)); | ||
} | ||
|
||
@Test | ||
public void RoomName_getRoomDisplayName_noLL_invitation() { | ||
RoomName_getRoomDisplayName_invitation(false); | ||
} | ||
|
||
@Test | ||
public void RoomName_getRoomDisplayName_LL_invitation() { | ||
RoomName_getRoomDisplayName_invitation(true); | ||
} | ||
|
||
private void RoomName_getRoomDisplayName_invitation(boolean withLazyLoading) { | ||
Context context = InstrumentationRegistry.getContext(); | ||
|
||
Room room; | ||
|
||
// Only me in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 1, true); | ||
Assert.assertEquals("Room Invite", room.getRoomDisplayName(context)); | ||
|
||
// One other user in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 2, true); | ||
Assert.assertEquals("Invite from UserName_2", room.getRoomDisplayName(context)); | ||
|
||
// 2 other users in the room | ||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 3, true); | ||
Assert.assertEquals("Invite from UserName_2", room.getRoomDisplayName(context)); | ||
|
||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 4, true); | ||
Assert.assertEquals("Invite from UserName_2", room.getRoomDisplayName(context)); | ||
|
||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 5, true); | ||
Assert.assertEquals("Invite from UserName_2", room.getRoomDisplayName(context)); | ||
|
||
room = mRoomTestHelper.createRoom(context, withLazyLoading, 10, true); | ||
Assert.assertEquals("Invite from UserName_2", room.getRoomDisplayName(context)); | ||
} | ||
} |
Oops, something went wrong.