From 5c66322dc6abb2a42092f844ea87a12de517ed97 Mon Sep 17 00:00:00 2001 From: Rafael Bischof Date: Wed, 19 Dec 2018 00:12:52 +0100 Subject: [PATCH 1/4] Replaced attrubutes enum by simply final values --- .../SDP/auth/AccountCreationActivity.java | 11 +-- .../ch/epfl/sweng/SDP/auth/LoginActivity.java | 5 +- .../sweng/SDP/firebase/AccountAttributes.java | 59 ++++---------- .../epfl/sweng/SDP/firebase/FbDatabase.java | 80 ++++++++----------- .../sweng/SDP/firebase/RoomAttributes.java | 48 +++-------- .../sweng/SDP/home/leaderboard/Player.java | 28 ++++--- .../ch/epfl/sweng/SDP/utils/OnlineStatus.java | 5 +- .../firebase/AccountAttributesUnitTest.java | 27 +++---- .../SDP/firebase/RoomAttributesUnitTest.java | 21 +++-- 9 files changed, 111 insertions(+), 173 deletions(-) diff --git a/app/src/main/java/ch/epfl/sweng/SDP/auth/AccountCreationActivity.java b/app/src/main/java/ch/epfl/sweng/SDP/auth/AccountCreationActivity.java index 10edaaae..90dffbdc 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/auth/AccountCreationActivity.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/auth/AccountCreationActivity.java @@ -1,8 +1,5 @@ package ch.epfl.sweng.SDP.auth; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.EMAIL; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.attributeToPath; - import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.VisibleForTesting; @@ -10,13 +7,17 @@ import android.widget.Button; import android.widget.EditText; import android.widget.TextView; + +import com.google.firebase.database.DataSnapshot; + import ch.epfl.sweng.SDP.NoBackPressActivity; import ch.epfl.sweng.SDP.R; import ch.epfl.sweng.SDP.firebase.FbDatabase; import ch.epfl.sweng.SDP.firebase.OnSuccessValueEventListener; import ch.epfl.sweng.SDP.home.HomeActivity; import ch.epfl.sweng.SDP.utils.GlideUtils; -import com.google.firebase.database.DataSnapshot; + +import static ch.epfl.sweng.SDP.firebase.AccountAttributes.EMAIL; /** * Class representing the account creation page. @@ -33,7 +34,7 @@ protected void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_account_creation); overridePendingTransition(R.anim.fade_in, R.anim.fade_out); - userEmail = getIntent().getStringExtra(attributeToPath(EMAIL)); + userEmail = getIntent().getStringExtra(EMAIL); usernameInput = findViewById(R.id.usernameInput); usernameTaken = findViewById(R.id.usernameTaken); diff --git a/app/src/main/java/ch/epfl/sweng/SDP/auth/LoginActivity.java b/app/src/main/java/ch/epfl/sweng/SDP/auth/LoginActivity.java index 00283c8e..2adc86ef 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/auth/LoginActivity.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/auth/LoginActivity.java @@ -21,7 +21,6 @@ import static android.view.View.VISIBLE; import static ch.epfl.sweng.SDP.firebase.AccountAttributes.EMAIL; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.attributeToPath; /** @@ -87,7 +86,7 @@ private void handleSuccessfulSignIn(IdpResponse response) { // New user Log.d(TAG, "New user"); Intent intent = new Intent(this, AccountCreationActivity.class); - intent.putExtra(attributeToPath(EMAIL), email); + intent.putExtra(EMAIL, email); startActivity(intent); finish(); } else { @@ -106,7 +105,7 @@ public void onDataChange(@NonNull DataSnapshot snapshot) { Log.d(TAG, "User signed in but not did not create an account"); Intent intent = new Intent(getApplicationContext(), AccountCreationActivity.class); - intent.putExtra(attributeToPath(EMAIL), email); + intent.putExtra(EMAIL, email); startActivity(intent); finish(); } diff --git a/app/src/main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java b/app/src/main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java index aa6efd4a..b5c919a9 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java @@ -3,49 +3,22 @@ import ch.epfl.sweng.SDP.auth.Account; /** - * Enum representing all the {@link Account}'s attributes. + * Class representing all the {@link Account}'s attributes. */ -public enum AccountAttributes { - USER_ID, USERNAME, EMAIL, STARS, TROPHIES, LEAGUE, MATCHES_WON, MATCHES_TOTAL, - AVERAGE_RATING, MAX_TROPHIES, FRIENDS, STATUS, BOUGHT_ITEMS; +public final class AccountAttributes { + + public static final String USER_ID = "userId"; + public static final String USERNAME = "username"; + public static final String EMAIL = "email"; + public static final String STARS = "stars"; + public static final String TROPHIES = "trophies"; + public static final String LEAGUE = "currentLeague"; + public static final String MATCHES_WON = "matchesWon"; + public static final String MATCHES_TOTAL = "totalMatches"; + public static final String AVERAGE_RATING = "averageRating"; + public static final String MAX_TROPHIES = "maxTrophies"; + public static final String FRIENDS = "friends"; + public static final String STATUS = "online"; + public static final String BOUGHT_ITEMS = "boughtItems"; - /** - * Converts the given {@link AccountAttributes} to a string which can be used in a path (for a - * Firebase Database query, for example). - * - * @param accountAttribute the account attribute to convert - * @return a string representing the given attribute - */ - public static String attributeToPath(AccountAttributes accountAttribute) { - switch (accountAttribute) { - case USER_ID: - return "userId"; - case USERNAME: - return "username"; - case EMAIL: - return "email"; - case STARS: - return "stars"; - case TROPHIES: - return "trophies"; - case LEAGUE: - return "currentLeague"; - case MATCHES_WON: - return "matchesWon"; - case MATCHES_TOTAL: - return "totalMatches"; - case AVERAGE_RATING: - return "averageRating"; - case MAX_TROPHIES: - return "maxTrophies"; - case FRIENDS: - return "friends"; - case STATUS: - return "online"; - case BOUGHT_ITEMS: - return "boughtItems"; - default: - throw new IllegalArgumentException("Unknown attribute"); - } - } } diff --git a/app/src/main/java/ch/epfl/sweng/SDP/firebase/FbDatabase.java b/app/src/main/java/ch/epfl/sweng/SDP/firebase/FbDatabase.java index 4392350f..3ac6f7d6 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/firebase/FbDatabase.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/firebase/FbDatabase.java @@ -18,12 +18,10 @@ import static ch.epfl.sweng.SDP.firebase.AccountAttributes.FRIENDS; import static ch.epfl.sweng.SDP.firebase.AccountAttributes.STATUS; import static ch.epfl.sweng.SDP.firebase.AccountAttributes.USERNAME; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.attributeToPath; import static ch.epfl.sweng.SDP.firebase.RoomAttributes.FINISHED; import static ch.epfl.sweng.SDP.firebase.RoomAttributes.RANKING; import static ch.epfl.sweng.SDP.firebase.RoomAttributes.UPLOAD_DRAWING; import static ch.epfl.sweng.SDP.firebase.RoomAttributes.USERS; -import static ch.epfl.sweng.SDP.firebase.RoomAttributes.attributeToPath; import static ch.epfl.sweng.SDP.utils.OnlineStatus.OFFLINE; import static ch.epfl.sweng.SDP.utils.Preconditions.checkPrecondition; @@ -80,12 +78,12 @@ public static void getUsers(ValueEventListener valueEventListener) { * Gets an attribute from a given user in the database. * * @param userId id of the user to get the attribute from - * @param attribute enum to determine which attribute to get + * @param attribute which attribute to get * @param valueEventListener listener to handle response */ - public static void getAccountAttribute(String userId, AccountAttributes attribute, + public static void getAccountAttribute(String userId, String attribute, ValueEventListener valueEventListener) { - getReference(constructUsersPath(userId, attributeToPath(attribute))) + getReference(constructUsersPath(userId, attribute)) .addListenerForSingleValueEvent(valueEventListener); } @@ -93,14 +91,14 @@ public static void getAccountAttribute(String userId, AccountAttributes attribut * Modifies (or inserts) the value of a given attribute in the database. * * @param userId id of the user whose attribute to modify - * @param attribute enum to determine which attribute to modify + * @param attribute which attribute to modify * @param newValue new value to be inserted for attribute * @param completionListener listener to handle response */ public static void setAccountAttribute( - String userId, AccountAttributes attribute, Object newValue, + String userId, String attribute, Object newValue, DatabaseReference.CompletionListener completionListener) { - getReference(constructUsersPath(userId, attributeToPath(attribute))) + getReference(constructUsersPath(userId, attribute)) .setValue(newValue, completionListener); } @@ -112,15 +110,15 @@ public static void setAccountAttribute( * @param newValue new value to be inserted for attribute */ public static void setAccountAttribute(String userId, - AccountAttributes attribute, Object newValue) { + String attribute, Object newValue) { setAccountAttribute(userId, attribute, newValue, createCompletionListener()); } /** * Removes an attribute from a given user. */ - public static void removeAccountAttribute(String userId, AccountAttributes attribute) { - getReference(constructUsersPath(userId, attributeToPath(attribute))).removeValue(); + public static void removeAccountAttribute(String userId, String attribute) { + getReference(constructUsersPath(userId, attribute)).removeValue(); } /** @@ -142,7 +140,7 @@ public static void getUserById(String userId, ValueEventListener valueEventListe * @param valueEventListener action that should be taken after retrieving the user */ public static void getUserByUsername(String username, ValueEventListener valueEventListener) { - USERS_REFERENCE.orderByChild(attributeToPath(USERNAME)).equalTo(username) + USERS_REFERENCE.orderByChild(USERNAME).equalTo(username) .addListenerForSingleValueEvent(valueEventListener); } @@ -154,7 +152,7 @@ public static void getUserByUsername(String username, ValueEventListener valueEv * @param valueEventListener action that should be taken after retrieving the user */ public static void getUserByEmail(String email, ValueEventListener valueEventListener) { - USERS_REFERENCE.orderByChild(attributeToPath(EMAIL)).equalTo(email) + USERS_REFERENCE.orderByChild(EMAIL).equalTo(email) .addListenerForSingleValueEvent(valueEventListener); } @@ -166,7 +164,7 @@ public static void getUserByEmail(String email, ValueEventListener valueEventLis * @param valueEventListener action that should be taken after retrieving the friends */ public static void getAllFriends(String userId, ValueEventListener valueEventListener) { - getReference(constructUsersPath(userId, attributeToPath(FRIENDS))) + getReference(constructUsersPath(userId, FRIENDS)) .addListenerForSingleValueEvent(valueEventListener); } @@ -177,7 +175,7 @@ public static void getAllFriends(String userId, ValueEventListener valueEventLis */ public static void getFriend(String userId, String friendId, ValueEventListener valueEventListener) { - getReference(constructUsersPath(userId, attributeToPath(FRIENDS), friendId)) + getReference(constructUsersPath(userId, FRIENDS, friendId)) .addListenerForSingleValueEvent(valueEventListener); } @@ -189,7 +187,7 @@ public static void getFriend(String userId, String friendId, * @param newValue new status of friendship */ public static void setFriendValue(String userId, String friendId, int newValue) { - getReference(constructUsersPath(userId, attributeToPath(FRIENDS), friendId)) + getReference(constructUsersPath(userId, FRIENDS, friendId)) .setValue(newValue, createCompletionListener()); } @@ -200,7 +198,7 @@ public static void setFriendValue(String userId, String friendId, int newValue) * @param friendId id of friend to be removed */ public static void removeFriend(String userId, String friendId) { - getReference(constructUsersPath(userId, attributeToPath(FRIENDS), friendId)) + getReference(constructUsersPath(userId, FRIENDS, friendId)) .removeValue(createCompletionListener()); } @@ -211,7 +209,7 @@ public static void removeFriend(String userId, String friendId) { * @param item item that will be inserted */ public static void setShopItemValue(String userId, ShopItem item) { - getReference(constructUsersPath(userId, attributeToPath(BOUGHT_ITEMS), + getReference(constructUsersPath(userId, BOUGHT_ITEMS, item.getColorItem().toString())) .setValue(item.getPriceItem(), createCompletionListener()); } @@ -223,9 +221,9 @@ public static void setShopItemValue(String userId, ShopItem item) { * @param attribute enum to determine which attribute to observe * @param valueEventListener listener to add */ - public static void setListenerToAccountAttribute(String userId, AccountAttributes attribute, + public static void setListenerToAccountAttribute(String userId, String attribute, ValueEventListener valueEventListener) { - getReference(constructUsersPath(userId, attributeToPath(attribute))) + getReference(constructUsersPath(userId, attribute)) .addValueEventListener(valueEventListener); } @@ -237,8 +235,8 @@ public static void setListenerToAccountAttribute(String userId, AccountAttribute * @param valueEventListener listener to remove */ public static void removeListenerFromAccountAttribute( - String userId, AccountAttributes attribute, ValueEventListener valueEventListener) { - getReference(constructUsersPath(userId, attributeToPath(attribute))) + String userId, String attribute, ValueEventListener valueEventListener) { + getReference(constructUsersPath(userId, attribute)) .removeEventListener(valueEventListener); } @@ -249,9 +247,9 @@ public static void removeListenerFromAccountAttribute( * @param attribute attribute to get * @param valueEventListener listener to run on completion */ - public static void getRoomAttribute(String roomId, RoomAttributes attribute, + public static void getRoomAttribute(String roomId, String attribute, ValueEventListener valueEventListener) { - getReference(constructRoomsPath(roomId, attributeToPath(attribute))) + getReference(constructRoomsPath(roomId, attribute)) .addListenerForSingleValueEvent(valueEventListener); } @@ -264,8 +262,8 @@ public static void getRoomAttribute(String roomId, RoomAttributes attribute, * @param newValue associated to the user */ public static void setValueToUserInRoomAttribute(String roomId, String username, - RoomAttributes attribute, Object newValue) { - getReference(constructRoomsPath(roomId, attributeToPath(attribute), username)) + String attribute, Object newValue) { + getReference(constructRoomsPath(roomId, attribute, username)) .setValue(newValue); } @@ -276,17 +274,10 @@ public static void setValueToUserInRoomAttribute(String roomId, String username, * @param account user that should be deleted */ public static void removeUserFromRoom(String roomId, Account account) { - getReference(constructRoomsPath(roomId, - attributeToPath(USERS), account.getUserId())) - .removeValue(); - getReference(constructRoomsPath(roomId, - attributeToPath(RANKING), account.getUsername())) - .removeValue(); - getReference(constructRoomsPath(roomId, - attributeToPath(FINISHED), account.getUsername())) - .removeValue(); - getReference(constructRoomsPath(roomId, - attributeToPath(UPLOAD_DRAWING), account.getUsername())) + getReference(constructRoomsPath(roomId, USERS, account.getUserId())).removeValue(); + getReference(constructRoomsPath(roomId, RANKING, account.getUsername())).removeValue(); + getReference(constructRoomsPath(roomId, FINISHED, account.getUsername())).removeValue(); + getReference(constructRoomsPath(roomId, UPLOAD_DRAWING, account.getUsername())) .removeValue(); } @@ -297,27 +288,26 @@ public static void removeUserFromRoom(String roomId, Account account) { * @param attribute enum to determine which attribute to observe * @param valueEventListener listener to handle response */ - public static void setListenerToRoomAttribute(String roomId, RoomAttributes attribute, + public static void setListenerToRoomAttribute(String roomId, String attribute, ValueEventListener valueEventListener) { - getReference(constructRoomsPath(roomId, attributeToPath(attribute))) + getReference(constructRoomsPath(roomId, attribute)) .addValueEventListener(valueEventListener); } /** * Removes a listener from an attribute of a given room. */ - public static void removeListenerFromRoomAttribute(String roomId, RoomAttributes attribute, + public static void removeListenerFromRoomAttribute(String roomId, String attribute, ValueEventListener valueEventListener) { - getReference(constructRoomsPath(roomId, attributeToPath(attribute))) + getReference(constructRoomsPath(roomId, attribute)) .removeEventListener(valueEventListener); } /** * Returns the {@link DatabaseReference} of an attribute in a given room. */ - public static DatabaseReference getRoomAttributeReference(String roomId, - RoomAttributes attribute) { - return getReference(constructRoomsPath(roomId, attributeToPath(attribute))); + public static DatabaseReference getRoomAttributeReference(String roomId, String attribute) { + return getReference(constructRoomsPath(roomId, attribute)); } /** @@ -326,7 +316,7 @@ public static DatabaseReference getRoomAttributeReference(String roomId, * @param userId id of user whose online value will be set to offline upon disconnection */ public static void changeToOfflineOnDisconnect(String userId) { - FbDatabase.getReference(constructUsersPath(userId, attributeToPath(STATUS))) + FbDatabase.getReference(constructUsersPath(userId, STATUS)) .onDisconnect() .setValue(OFFLINE.ordinal()); } diff --git a/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java b/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java index 0902c814..2c90e076 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java @@ -3,41 +3,17 @@ /** * Enum representing all the room's attributes. */ -public enum RoomAttributes { - FINISHED, GAME_MODE, ONLINE_STATUS, PLAYING, RANKING, STATE, - TIMER, UPLOAD_DRAWING, USERS, WORDS; +public final class RoomAttributes { + + public static final String FINISHED = "finished"; + public static final String GAME_MODE = "gameMode"; + public static final String ONLINE_STATUS = "onlineStatus"; + public static final String PLAYING = "playing"; + public static final String RANKING = "ranking"; + public static final String STATE = "state"; + public static final String TIMER = "timer.observableTime"; + public static final String UPLOAD_DRAWING = "uploadDrawing"; + public static final String USERS = "users"; + public static final String WORDS = "words"; - /** - * Converts the given {@link RoomAttributes} to a string which can be used in a path (for a - * Firebase Database query, for example). - * - * @param roomAttributes the account attribute to convert - * @return a string representing the given attribute - */ - static String attributeToPath(RoomAttributes roomAttributes) { - switch (roomAttributes) { - case FINISHED: - return "finished"; - case GAME_MODE: - return "gameMode"; - case ONLINE_STATUS: - return "onlineStatus"; - case PLAYING: - return "playing"; - case RANKING: - return "ranking"; - case STATE: - return "state"; - case TIMER: - return "timer.observableTime"; - case UPLOAD_DRAWING: - return "uploadDrawing"; - case USERS: - return "users"; - case WORDS: - return "words"; - default: - throw new IllegalArgumentException("Unknown attribute"); - } - } } diff --git a/app/src/main/java/ch/epfl/sweng/SDP/home/leaderboard/Player.java b/app/src/main/java/ch/epfl/sweng/SDP/home/leaderboard/Player.java index bea2a732..ad53df04 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/home/leaderboard/Player.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/home/leaderboard/Player.java @@ -1,12 +1,5 @@ package ch.epfl.sweng.SDP.home.leaderboard; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.LEAGUE; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.TROPHIES; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.USERNAME; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.USER_ID; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.attributeToPath; -import static ch.epfl.sweng.SDP.utils.LayoutUtils.getLeagueImageId; - import android.content.Context; import android.content.res.Resources; import android.view.View; @@ -14,12 +7,21 @@ import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; + +import com.google.firebase.database.DataSnapshot; + +import java.util.LinkedList; + import ch.epfl.sweng.SDP.R; import ch.epfl.sweng.SDP.auth.Account; import ch.epfl.sweng.SDP.utils.TestUsers; import ch.epfl.sweng.SDP.utils.TypefaceLibrary; -import com.google.firebase.database.DataSnapshot; -import java.util.LinkedList; + +import static ch.epfl.sweng.SDP.firebase.AccountAttributes.LEAGUE; +import static ch.epfl.sweng.SDP.firebase.AccountAttributes.TROPHIES; +import static ch.epfl.sweng.SDP.firebase.AccountAttributes.USERNAME; +import static ch.epfl.sweng.SDP.firebase.AccountAttributes.USER_ID; +import static ch.epfl.sweng.SDP.utils.LayoutUtils.getLeagueImageId; /** * Helper class to manage and display user data from Firebase. @@ -143,10 +145,10 @@ void setRank(int rank) { */ static void convertSnapshotToPlayerAndAddToList(Context context, DataSnapshot snapshot, LinkedList players) { - String userId = snapshot.child(attributeToPath(USER_ID)).getValue(String.class); - String username = snapshot.child(attributeToPath(USERNAME)).getValue(String.class); - Long trophies = snapshot.child(attributeToPath(TROPHIES)).getValue(Long.class); - String league = snapshot.child(attributeToPath(LEAGUE)).getValue(String.class); + String userId = snapshot.child(USER_ID).getValue(String.class); + String username = snapshot.child(USERNAME).getValue(String.class); + Long trophies = snapshot.child(TROPHIES).getValue(Long.class); + String league = snapshot.child(LEAGUE).getValue(String.class); if (!TestUsers.isTestUser(snapshot.getKey()) && userId != null && username != null diff --git a/app/src/main/java/ch/epfl/sweng/SDP/utils/OnlineStatus.java b/app/src/main/java/ch/epfl/sweng/SDP/utils/OnlineStatus.java index 2c1d6f6c..32f9dc27 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/utils/OnlineStatus.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/utils/OnlineStatus.java @@ -2,9 +2,9 @@ import com.google.firebase.database.DatabaseReference; -import ch.epfl.sweng.SDP.firebase.AccountAttributes; import ch.epfl.sweng.SDP.firebase.FbDatabase; +import static ch.epfl.sweng.SDP.firebase.AccountAttributes.STATUS; import static ch.epfl.sweng.SDP.utils.Preconditions.checkPrecondition; /** @@ -47,8 +47,7 @@ public static void changeOnlineStatus(String userId, OnlineStatus status, checkPrecondition(status == OFFLINE || status == ONLINE, "Wrong status given"); - FbDatabase.setAccountAttribute(userId, - AccountAttributes.STATUS, status.ordinal(), listener); + FbDatabase.setAccountAttribute(userId, STATUS, status.ordinal(), listener); } /** diff --git a/app/src/test/java/ch/epfl/sweng/SDP/firebase/AccountAttributesUnitTest.java b/app/src/test/java/ch/epfl/sweng/SDP/firebase/AccountAttributesUnitTest.java index bbf20b38..9de54a91 100644 --- a/app/src/test/java/ch/epfl/sweng/SDP/firebase/AccountAttributesUnitTest.java +++ b/app/src/test/java/ch/epfl/sweng/SDP/firebase/AccountAttributesUnitTest.java @@ -15,7 +15,6 @@ import static ch.epfl.sweng.SDP.firebase.AccountAttributes.TROPHIES; import static ch.epfl.sweng.SDP.firebase.AccountAttributes.USERNAME; import static ch.epfl.sweng.SDP.firebase.AccountAttributes.USER_ID; -import static ch.epfl.sweng.SDP.firebase.AccountAttributes.attributeToPath; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -24,18 +23,18 @@ public class AccountAttributesUnitTest { @Test public void testAttributeToPathReturnsCorrectPath() { - assertThat(attributeToPath(USER_ID), is(equalTo("userId"))); - assertThat(attributeToPath(USERNAME), is(equalTo("username"))); - assertThat(attributeToPath(EMAIL), is(equalTo("email"))); - assertThat(attributeToPath(STARS), is(equalTo("stars"))); - assertThat(attributeToPath(TROPHIES), is(equalTo("trophies"))); - assertThat(attributeToPath(LEAGUE), is(equalTo("currentLeague"))); - assertThat(attributeToPath(MATCHES_WON), is(equalTo("matchesWon"))); - assertThat(attributeToPath(MATCHES_TOTAL), is(equalTo("totalMatches"))); - assertThat(attributeToPath(AVERAGE_RATING), is(equalTo("averageRating"))); - assertThat(attributeToPath(MAX_TROPHIES), is(equalTo("maxTrophies"))); - assertThat(attributeToPath(FRIENDS), is(equalTo("friends"))); - assertThat(attributeToPath(STATUS), is(equalTo("online"))); - assertThat(attributeToPath(BOUGHT_ITEMS), is(equalTo("boughtItems"))); + assertThat(USER_ID, is(equalTo("userId"))); + assertThat(USERNAME, is(equalTo("username"))); + assertThat(EMAIL, is(equalTo("email"))); + assertThat(STARS, is(equalTo("stars"))); + assertThat(TROPHIES, is(equalTo("trophies"))); + assertThat(LEAGUE, is(equalTo("currentLeague"))); + assertThat(MATCHES_WON, is(equalTo("matchesWon"))); + assertThat(MATCHES_TOTAL, is(equalTo("totalMatches"))); + assertThat(AVERAGE_RATING, is(equalTo("averageRating"))); + assertThat(MAX_TROPHIES, is(equalTo("maxTrophies"))); + assertThat(FRIENDS, is(equalTo("friends"))); + assertThat(STATUS, is(equalTo("online"))); + assertThat(BOUGHT_ITEMS, is(equalTo("boughtItems"))); } } \ No newline at end of file diff --git a/app/src/test/java/ch/epfl/sweng/SDP/firebase/RoomAttributesUnitTest.java b/app/src/test/java/ch/epfl/sweng/SDP/firebase/RoomAttributesUnitTest.java index 14600bb3..c73d4c19 100644 --- a/app/src/test/java/ch/epfl/sweng/SDP/firebase/RoomAttributesUnitTest.java +++ b/app/src/test/java/ch/epfl/sweng/SDP/firebase/RoomAttributesUnitTest.java @@ -12,7 +12,6 @@ import static ch.epfl.sweng.SDP.firebase.RoomAttributes.UPLOAD_DRAWING; import static ch.epfl.sweng.SDP.firebase.RoomAttributes.USERS; import static ch.epfl.sweng.SDP.firebase.RoomAttributes.WORDS; -import static ch.epfl.sweng.SDP.firebase.RoomAttributes.attributeToPath; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; @@ -21,16 +20,16 @@ public class RoomAttributesUnitTest { @Test public void testAttributeToPathReturnsCorrectPath() { - assertThat(attributeToPath(FINISHED), is(equalTo("finished"))); - assertThat(attributeToPath(GAME_MODE), is(equalTo("gameMode"))); - assertThat(attributeToPath(ONLINE_STATUS), is(equalTo("onlineStatus"))); - assertThat(attributeToPath(PLAYING), is(equalTo("playing"))); - assertThat(attributeToPath(RANKING), is(equalTo("ranking"))); - assertThat(attributeToPath(STATE), is(equalTo("state"))); - assertThat(attributeToPath(TIMER), is(equalTo("timer.observableTime"))); - assertThat(attributeToPath(UPLOAD_DRAWING), is(equalTo("uploadDrawing"))); - assertThat(attributeToPath(USERS), is(equalTo("users"))); - assertThat(attributeToPath(WORDS), is(equalTo("words"))); + assertThat(FINISHED, is(equalTo("finished"))); + assertThat(GAME_MODE, is(equalTo("gameMode"))); + assertThat(ONLINE_STATUS, is(equalTo("onlineStatus"))); + assertThat(PLAYING, is(equalTo("playing"))); + assertThat(RANKING, is(equalTo("ranking"))); + assertThat(STATE, is(equalTo("state"))); + assertThat(TIMER, is(equalTo("timer.observableTime"))); + assertThat(UPLOAD_DRAWING, is(equalTo("uploadDrawing"))); + assertThat(USERS, is(equalTo("users"))); + assertThat(WORDS, is(equalTo("words"))); } } \ No newline at end of file From aa4b77bc64d6650abf780dad2fe8c40a10fd22c6 Mon Sep 17 00:00:00 2001 From: Rafael Bischof Date: Wed, 19 Dec 2018 00:17:04 +0100 Subject: [PATCH 2/4] Updated javadoc --- .../java/ch/epfl/sweng/SDP/firebase/FbDatabase.java | 10 +++++----- .../ch/epfl/sweng/SDP/firebase/RoomAttributes.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/ch/epfl/sweng/SDP/firebase/FbDatabase.java b/app/src/main/java/ch/epfl/sweng/SDP/firebase/FbDatabase.java index 3ac6f7d6..9e576a0a 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/firebase/FbDatabase.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/firebase/FbDatabase.java @@ -106,7 +106,7 @@ public static void setAccountAttribute( * Same as {@link #setAccountAttribute}, but with a default completionListener. * * @param userId id of user whose attribute to modify - * @param attribute enum to determine which attribute to modify + * @param attribute which attribute to modify * @param newValue new value to be inserted for attribute */ public static void setAccountAttribute(String userId, @@ -218,7 +218,7 @@ public static void setShopItemValue(String userId, ShopItem item) { * Sets a listener to an attribute of a given user. * * @param userId id of user whose attribute will be observed - * @param attribute enum to determine which attribute to observe + * @param attribute which attribute to observe * @param valueEventListener listener to add */ public static void setListenerToAccountAttribute(String userId, String attribute, @@ -231,7 +231,7 @@ public static void setListenerToAccountAttribute(String userId, String attribute * Removes the listener to an attribute of a given user. * * @param userId id of user whose attribute won't be observed anymore - * @param attribute enum to determine which attribute's listener to remove + * @param attribute which attribute's listener to remove * @param valueEventListener listener to remove */ public static void removeListenerFromAccountAttribute( @@ -244,7 +244,7 @@ public static void removeListenerFromAccountAttribute( * Gets an attribute from a given room in the database. * * @param roomId id of the room to get the attribute from - * @param attribute attribute to get + * @param attribute which attribute to get * @param valueEventListener listener to run on completion */ public static void getRoomAttribute(String roomId, String attribute, @@ -285,7 +285,7 @@ public static void removeUserFromRoom(String roomId, Account account) { * Sets a listener to an attribute of a given room. * * @param roomId id of room whose attribute will be observed - * @param attribute enum to determine which attribute to observe + * @param attribute which attribute to observe * @param valueEventListener listener to handle response */ public static void setListenerToRoomAttribute(String roomId, String attribute, diff --git a/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java b/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java index 2c90e076..1fb7e220 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java @@ -1,7 +1,7 @@ package ch.epfl.sweng.SDP.firebase; /** - * Enum representing all the room's attributes. + * Class representing all the room's attributes. */ public final class RoomAttributes { From 065430cc1fd87598bf5dffa6ddfef8708333685a Mon Sep 17 00:00:00 2001 From: Rafael Bischof Date: Wed, 19 Dec 2018 00:21:01 +0100 Subject: [PATCH 3/4] Added private constructor to RoomAttributes --- .../main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java b/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java index 1fb7e220..1bd832e0 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/firebase/RoomAttributes.java @@ -5,6 +5,8 @@ */ public final class RoomAttributes { + private RoomAttributes() {} + public static final String FINISHED = "finished"; public static final String GAME_MODE = "gameMode"; public static final String ONLINE_STATUS = "onlineStatus"; From 281a5efc4ef0bee81bd7316d6cb5d51e8328ddd3 Mon Sep 17 00:00:00 2001 From: Rafael Bischof Date: Wed, 19 Dec 2018 00:21:21 +0100 Subject: [PATCH 4/4] Added private constructor to AccountAttributes --- .../main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/src/main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java b/app/src/main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java index b5c919a9..85a7f198 100644 --- a/app/src/main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java +++ b/app/src/main/java/ch/epfl/sweng/SDP/firebase/AccountAttributes.java @@ -7,6 +7,8 @@ */ public final class AccountAttributes { + private AccountAttributes() {} + public static final String USER_ID = "userId"; public static final String USERNAME = "username"; public static final String EMAIL = "email";