|
| 1 | +/* |
| 2 | + * Copyright (c) 2019 Livio, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Redistribution and use in source and binary forms, with or without |
| 6 | + * modification, are permitted provided that the following conditions are met: |
| 7 | + * |
| 8 | + * Redistributions of source code must retain the above copyright notice, this |
| 9 | + * list of conditions and the following disclaimer. |
| 10 | + * |
| 11 | + * Redistributions in binary form must reproduce the above copyright notice, |
| 12 | + * this list of conditions and the following |
| 13 | + * disclaimer in the documentation and/or other materials provided with the |
| 14 | + * distribution. |
| 15 | + * |
| 16 | + * Neither the name of the Livio Inc. nor the names of its contributors |
| 17 | + * may be used to endorse or promote products derived from this software |
| 18 | + * without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 24 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 25 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 26 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 27 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 28 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 29 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 30 | + * POSSIBILITY OF SUCH DAMAGE. |
| 31 | + */ |
| 32 | + |
| 33 | +package com.smartdevicelink.managers.file.filetypes; |
| 34 | + |
| 35 | +import com.smartdevicelink.test.TestValues; |
| 36 | + |
| 37 | +import org.junit.Test; |
| 38 | + |
| 39 | +import static junit.framework.TestCase.assertEquals; |
| 40 | +import static junit.framework.TestCase.assertFalse; |
| 41 | + |
| 42 | +public class SdlFileTests { |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testConstructorWithNoParams() { |
| 46 | + SdlFile sdlFile; |
| 47 | + |
| 48 | + // Case 1 (Setting data) |
| 49 | + sdlFile = new SdlFile(); |
| 50 | + sdlFile.setFileData(TestValues.GENERAL_BYTE_ARRAY); |
| 51 | + assertEquals(sdlFile.getFileData(), TestValues.GENERAL_BYTE_ARRAY); |
| 52 | + sdlFile.setName(null); |
| 53 | + assertEquals(sdlFile.getName(), "e9800998ecf8427e"); |
| 54 | + sdlFile.setName(TestValues.GENERAL_STRING); |
| 55 | + assertEquals(sdlFile.getName(), TestValues.GENERAL_STRING); |
| 56 | + sdlFile.setType(TestValues.GENERAL_FILETYPE); |
| 57 | + assertEquals(sdlFile.getType(), TestValues.GENERAL_FILETYPE); |
| 58 | + sdlFile.setPersistent(TestValues.GENERAL_BOOLEAN); |
| 59 | + assertEquals(sdlFile.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 60 | + assertFalse(sdlFile.getOverwrite()); |
| 61 | + |
| 62 | + // Case 2 (Setting resourceId) |
| 63 | + sdlFile = new SdlFile(); |
| 64 | + sdlFile.setFilePath(TestValues.GENERAL_STRING); |
| 65 | + assertEquals(sdlFile.getFilePath(), TestValues.GENERAL_STRING); |
| 66 | + sdlFile.setName(null); |
| 67 | + assertEquals(sdlFile.getName(), "cade4e832627b4f6"); |
| 68 | + sdlFile.setName(TestValues.GENERAL_STRING); |
| 69 | + assertEquals(sdlFile.getName(), TestValues.GENERAL_STRING); |
| 70 | + sdlFile.setType(TestValues.GENERAL_FILETYPE); |
| 71 | + assertEquals(sdlFile.getType(), TestValues.GENERAL_FILETYPE); |
| 72 | + sdlFile.setPersistent(TestValues.GENERAL_BOOLEAN); |
| 73 | + assertEquals(sdlFile.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 74 | + assertFalse(sdlFile.getOverwrite()); |
| 75 | + |
| 76 | + // Case 3 (Setting URI) |
| 77 | + sdlFile = new SdlFile(); |
| 78 | + sdlFile.setURI(TestValues.GENERAL_URI); |
| 79 | + assertEquals(sdlFile.getURI(), TestValues.GENERAL_URI); |
| 80 | + sdlFile.setName(null); |
| 81 | + assertEquals(sdlFile.getName(), "d3467db131372140"); |
| 82 | + sdlFile.setName(TestValues.GENERAL_STRING); |
| 83 | + assertEquals(sdlFile.getName(), TestValues.GENERAL_STRING); |
| 84 | + sdlFile.setType(TestValues.GENERAL_FILETYPE); |
| 85 | + assertEquals(sdlFile.getType(), TestValues.GENERAL_FILETYPE); |
| 86 | + sdlFile.setPersistent(TestValues.GENERAL_BOOLEAN); |
| 87 | + assertEquals(sdlFile.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 88 | + assertFalse(sdlFile.getOverwrite()); |
| 89 | + } |
| 90 | + |
| 91 | + @Test |
| 92 | + public void testConstructorWithResourceId() { |
| 93 | + // Case1 (Set the name manually) |
| 94 | + SdlFile sdlFile1 = new SdlFile(TestValues.GENERAL_STRING, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_STRING, TestValues.GENERAL_BOOLEAN); |
| 95 | + assertEquals(sdlFile1.getName(), TestValues.GENERAL_STRING); |
| 96 | + assertEquals(sdlFile1.getType(), TestValues.GENERAL_FILETYPE); |
| 97 | + assertEquals(sdlFile1.getFilePath(), TestValues.GENERAL_STRING); |
| 98 | + assertEquals(sdlFile1.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 99 | + assertFalse(sdlFile1.getOverwrite()); |
| 100 | + |
| 101 | + // Case2 (Let the library generate a name) |
| 102 | + SdlFile sdlFile2 = new SdlFile(null, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_STRING, TestValues.GENERAL_BOOLEAN); |
| 103 | + SdlFile sdlFile3 = new SdlFile(null, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_STRING, TestValues.GENERAL_BOOLEAN); |
| 104 | + assertEquals(sdlFile2.getName(), sdlFile3.getName()); |
| 105 | + assertEquals(sdlFile2.getName(), "cade4e832627b4f6"); |
| 106 | + assertEquals(sdlFile2.getType(), TestValues.GENERAL_FILETYPE); |
| 107 | + assertEquals(sdlFile2.getFilePath(), TestValues.GENERAL_STRING); |
| 108 | + assertEquals(sdlFile2.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 109 | + assertFalse(sdlFile2.getOverwrite()); |
| 110 | + } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void testConstructorWithData() { |
| 114 | + // Case1 (Set the name manually) |
| 115 | + SdlFile sdlFile1 = new SdlFile(TestValues.GENERAL_STRING, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_BYTE_ARRAY, TestValues.GENERAL_BOOLEAN); |
| 116 | + assertEquals(sdlFile1.getName(), TestValues.GENERAL_STRING); |
| 117 | + assertEquals(sdlFile1.getType(), TestValues.GENERAL_FILETYPE); |
| 118 | + assertEquals(sdlFile1.getFileData(), TestValues.GENERAL_BYTE_ARRAY); |
| 119 | + assertEquals(sdlFile1.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 120 | + assertFalse(sdlFile1.getOverwrite()); |
| 121 | + |
| 122 | + // Case2 (Let the library generate a name) |
| 123 | + SdlFile sdlFile2 = new SdlFile(null, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_BYTE_ARRAY, TestValues.GENERAL_BOOLEAN); |
| 124 | + SdlFile sdlFile3 = new SdlFile(null, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_BYTE_ARRAY, TestValues.GENERAL_BOOLEAN); |
| 125 | + assertEquals(sdlFile2.getName(), sdlFile3.getName()); |
| 126 | + assertEquals(sdlFile2.getName(), "e9800998ecf8427e"); |
| 127 | + assertEquals(sdlFile2.getType(), TestValues.GENERAL_FILETYPE); |
| 128 | + assertEquals(sdlFile2.getFileData(), TestValues.GENERAL_BYTE_ARRAY); |
| 129 | + assertEquals(sdlFile2.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 130 | + assertFalse(sdlFile2.getOverwrite()); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void testConstructorWithUri() { |
| 135 | + // Case1 (Set the name manually) |
| 136 | + SdlFile sdlFile1 = new SdlFile(TestValues.GENERAL_STRING, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_URI, TestValues.GENERAL_BOOLEAN); |
| 137 | + assertEquals(sdlFile1.getName(), TestValues.GENERAL_STRING); |
| 138 | + assertEquals(sdlFile1.getType(), TestValues.GENERAL_FILETYPE); |
| 139 | + assertEquals(sdlFile1.getURI(), TestValues.GENERAL_URI); |
| 140 | + assertEquals(sdlFile1.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 141 | + assertFalse(sdlFile1.getOverwrite()); |
| 142 | + |
| 143 | + // Case2 (Let the library generate a name) |
| 144 | + SdlFile sdlFile2 = new SdlFile(null, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_URI, TestValues.GENERAL_BOOLEAN); |
| 145 | + SdlFile sdlFile3 = new SdlFile(null, TestValues.GENERAL_FILETYPE, TestValues.GENERAL_URI, TestValues.GENERAL_BOOLEAN); |
| 146 | + assertEquals(sdlFile2.getName(), sdlFile3.getName()); |
| 147 | + assertEquals(sdlFile2.getName(), "d3467db131372140"); |
| 148 | + assertEquals(sdlFile2.getType(), TestValues.GENERAL_FILETYPE); |
| 149 | + assertEquals(sdlFile2.getURI(), TestValues.GENERAL_URI); |
| 150 | + assertEquals(sdlFile2.isPersistent(), TestValues.GENERAL_BOOLEAN); |
| 151 | + assertFalse(sdlFile2.getOverwrite()); |
| 152 | + } |
| 153 | +} |
0 commit comments