Browse Source

Merge pull request #3841 from nextcloud/owncloudsession-unit-tests

Unit tests for the OwnCloudSession class.
Andy Scherzinger 6 years ago
parent
commit
3d9e379b43

+ 10 - 31
src/main/java/com/owncloud/android/utils/OwnCloudSession.java

@@ -1,4 +1,4 @@
-/**
+/*
  * ownCloud Android client application
  *
  * @author Bartek Przybylski
@@ -19,37 +19,16 @@
  */
 package com.owncloud.android.utils;
 
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+import lombok.Setter;
+
 /**
  * Represents a session to an ownCloud instance
  */
-public class OwnCloudSession {
-    private String mSessionName;
-    private String mSessionUrl;
-    private int mEntryId;
-
-    public OwnCloudSession(String name, String url, int entryId) {
-        mSessionName = name;
-        mSessionUrl = url;
-        mEntryId = entryId;
-    }
-
-    public void setName(String name) {
-        mSessionName = name;
-    }
-
-    public String getName() {
-        return mSessionName;
-    }
-
-    public void setUrl(String url) {
-        mSessionUrl = url;
-    }
-
-    public String getUrl() {
-        return mSessionUrl;
-    }
-
-    public int getEntryId() {
-        return mEntryId;
-    }
+@AllArgsConstructor
+class OwnCloudSession {
+    @Getter @Setter private String sessionName;
+    @Getter @Setter private String sessionUrl;
+    @Getter private int entryId;
 }

+ 71 - 0
src/test/java/com/owncloud/android/utils/OwnCloudSessionTest.java

@@ -0,0 +1,71 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2019 Tobias Kaminsky
+ * Copyright (C) 2019 Edvard Holst
+ * Copyright (C) 2019 Nextcloud GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+package com.owncloud.android.utils;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class OwnCloudSessionTest {
+
+    private final String SESSION_NAME = "testSession";
+    private final String SESSION_URL = "https://test.cloud.local";
+    private final int SESSION_ID = 1;
+
+    private OwnCloudSession ownCloudSession = new OwnCloudSession(SESSION_NAME, SESSION_URL, SESSION_ID);
+
+    @Before
+    public void setUp() {
+        ownCloudSession.setSessionName(SESSION_NAME);
+        ownCloudSession.setSessionUrl(SESSION_URL);
+    }
+
+    @Test
+    public void setName_assertCorrectNameUpdated() {
+        String newName = "newTestSession";
+        ownCloudSession.setSessionName(newName);
+        assertEquals("OwnCloud session name not updated", newName, ownCloudSession.getSessionName());
+    }
+
+    @Test
+    public void getName_assertCorrectNamedRetrieved() {
+        assertEquals("OwnCloudSession name not correct", SESSION_NAME, ownCloudSession.getSessionName());
+    }
+
+    @Test
+    public void setUrl_assertCorrectUrlUpdated() {
+        String newUrl = "https://new.cloud.local";
+        ownCloudSession.setSessionUrl(newUrl);
+        assertEquals("OwnCloud session URL not updated", newUrl, ownCloudSession.getSessionUrl());
+    }
+
+    @Test
+    public void getUrl_assertCorrectUrlRetrieved() {
+        assertEquals("OwnCloudSession URL not correct", SESSION_URL, ownCloudSession.getSessionUrl());
+    }
+
+    @Test
+    public void getEntryId_assertCorrectIdRetrieved() {
+        assertEquals("OwnCloudSession ID is incorrect", SESSION_ID, ownCloudSession.getEntryId());
+    }
+}