Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package androidx.car.app.navigation.model; |
| 18 | |
| 19 | import static androidx.car.app.navigation.model.Maneuver.TYPE_DESTINATION_LEFT; |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 20 | import static androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW; |
| 21 | import static androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE; |
| 22 | import static androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW; |
| 23 | import static androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE; |
Billy Lam | d5488f4 | 2020-11-23 22:54:47 -0800 | [diff] [blame] | 24 | import static androidx.car.app.navigation.model.Maneuver.TYPE_ROUNDABOUT_ENTER_CW; |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 25 | import static androidx.car.app.navigation.model.Maneuver.TYPE_STRAIGHT; |
| 26 | |
| 27 | import static com.google.common.truth.Truth.assertThat; |
| 28 | |
| 29 | import static org.junit.Assert.assertThrows; |
| 30 | |
| 31 | import android.content.ContentResolver; |
| 32 | import android.net.Uri; |
| 33 | |
| 34 | import androidx.car.app.model.CarIcon; |
| 35 | import androidx.core.graphics.drawable.IconCompat; |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 36 | |
| 37 | import org.junit.Test; |
| 38 | import org.junit.runner.RunWith; |
Ram Parameswaran | 1384d51 | 2020-12-01 22:08:21 -0800 | [diff] [blame] | 39 | import org.robolectric.RobolectricTestRunner; |
| 40 | import org.robolectric.annotation.internal.DoNotInstrument; |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 41 | |
| 42 | /** Tests for {@link Maneuver}. */ |
Ram Parameswaran | 1384d51 | 2020-12-01 22:08:21 -0800 | [diff] [blame] | 43 | @RunWith(RobolectricTestRunner.class) |
| 44 | @DoNotInstrument |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 45 | public class ManeuverTest { |
| 46 | |
| 47 | @Test |
| 48 | public void createInstance_non_roundabout() { |
| 49 | int type = TYPE_STRAIGHT; |
| 50 | |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 51 | Maneuver maneuver = new Maneuver.Builder(type).setIcon(CarIcon.APP_ICON).build(); |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 52 | assertThat(type).isEqualTo(maneuver.getType()); |
| 53 | assertThat(CarIcon.APP_ICON).isEqualTo(maneuver.getIcon()); |
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | public void createInstance_non_roundabout_invalid_type() { |
| 58 | int typeHigh = 1000; |
| 59 | assertThrows( |
| 60 | IllegalArgumentException.class, |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 61 | () -> new Maneuver.Builder(typeHigh).setIcon(CarIcon.APP_ICON).build()); |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 62 | |
| 63 | int typeLow = -1; |
| 64 | assertThrows( |
| 65 | IllegalArgumentException.class, |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 66 | () -> new Maneuver.Builder(typeLow).setIcon(CarIcon.APP_ICON).build()); |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | @Test |
| 70 | public void createInstance_non_roundabout_roundabout_type() { |
| 71 | assertThrows( |
| 72 | IllegalArgumentException.class, |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 73 | () -> new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW).setIcon( |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 74 | CarIcon.APP_ICON).build()); |
| 75 | assertThrows( |
| 76 | IllegalArgumentException.class, |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 77 | () -> new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW).setIcon( |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 78 | CarIcon.APP_ICON).build()); |
| 79 | assertThrows(IllegalArgumentException.class, |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 80 | () -> new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW_WITH_ANGLE) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 81 | .setIcon(CarIcon.APP_ICON) |
| 82 | .build()); |
| 83 | assertThrows( |
| 84 | IllegalArgumentException.class, |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 85 | () -> new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 86 | .setIcon(CarIcon.APP_ICON) |
| 87 | .build()); |
| 88 | } |
| 89 | |
| 90 | @Test |
| 91 | public void createInstance_roundabout_only_exit_number() { |
| 92 | int type = TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW; |
| 93 | int roundaboutExitNumber = 2; |
| 94 | |
| 95 | Maneuver maneuver = |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 96 | new Maneuver.Builder(type) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 97 | .setRoundaboutExitNumber(roundaboutExitNumber) |
| 98 | .setIcon(CarIcon.APP_ICON) |
| 99 | .build(); |
| 100 | assertThat(type).isEqualTo(maneuver.getType()); |
| 101 | assertThat(roundaboutExitNumber).isEqualTo(maneuver.getRoundaboutExitNumber()); |
| 102 | assertThat(CarIcon.APP_ICON).isEqualTo(maneuver.getIcon()); |
| 103 | } |
| 104 | |
| 105 | @Test |
| 106 | public void createInstance_roundabout_invalid_type() { |
| 107 | int typeHigh = 1000; |
| 108 | assertThrows( |
| 109 | IllegalArgumentException.class, |
| 110 | () -> |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 111 | new Maneuver.Builder(typeHigh) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 112 | .setRoundaboutExitNumber(1) |
| 113 | .setIcon(CarIcon.APP_ICON) |
| 114 | .build()); |
| 115 | |
| 116 | int typeLow = -1; |
| 117 | assertThrows( |
| 118 | IllegalArgumentException.class, |
| 119 | () -> |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 120 | new Maneuver.Builder(typeLow).setRoundaboutExitNumber(1).setIcon( |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 121 | CarIcon.APP_ICON).build()); |
| 122 | } |
| 123 | |
| 124 | @Test |
| 125 | public void createInstance_roundabout_non_roundabout_type() { |
| 126 | int type = TYPE_STRAIGHT; |
| 127 | assertThrows( |
| 128 | IllegalArgumentException.class, |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 129 | () -> new Maneuver.Builder(type).setRoundaboutExitNumber(1).setIcon( |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 130 | CarIcon.APP_ICON).build()); |
| 131 | } |
| 132 | |
| 133 | @Test |
| 134 | public void createInstance_roundabout_invalid_exit() { |
| 135 | int type = TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW; |
| 136 | int roundaboutExitNumber = 0; |
| 137 | |
| 138 | assertThrows( |
| 139 | IllegalArgumentException.class, |
| 140 | () -> |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 141 | new Maneuver.Builder(type) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 142 | .setRoundaboutExitNumber(roundaboutExitNumber) |
| 143 | .setIcon(CarIcon.APP_ICON) |
| 144 | .build()); |
| 145 | } |
| 146 | |
| 147 | @Test |
| 148 | public void createInstance_roundabout_with_angle() { |
| 149 | int type = TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE; |
| 150 | int roundaboutExitNumber = 3; |
| 151 | int roundaboutExitAngle = 270; |
| 152 | |
| 153 | Maneuver maneuver = |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 154 | new Maneuver.Builder(type) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 155 | .setRoundaboutExitNumber(roundaboutExitNumber) |
| 156 | .setRoundaboutExitAngle(roundaboutExitAngle) |
| 157 | .setIcon(CarIcon.APP_ICON) |
| 158 | .build(); |
| 159 | assertThat(type).isEqualTo(maneuver.getType()); |
| 160 | assertThat(roundaboutExitNumber).isEqualTo(maneuver.getRoundaboutExitNumber()); |
| 161 | assertThat(roundaboutExitAngle).isEqualTo(maneuver.getRoundaboutExitAngle()); |
| 162 | assertThat(CarIcon.APP_ICON).isEqualTo(maneuver.getIcon()); |
| 163 | } |
| 164 | |
| 165 | @Test |
Billy Lam | 994257a | 2022-01-14 16:42:06 -0800 | [diff] [blame] | 166 | public void createInstance_roundabout_with_angle_optionalExitNumber() { |
| 167 | int type = TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW_WITH_ANGLE; |
| 168 | int roundaboutExitAngle = 270; |
| 169 | |
| 170 | Maneuver maneuver = |
| 171 | new Maneuver.Builder(type) |
| 172 | .setRoundaboutExitAngle(roundaboutExitAngle) |
| 173 | .setIcon(CarIcon.APP_ICON) |
| 174 | .build(); |
| 175 | assertThat(type).isEqualTo(maneuver.getType()); |
| 176 | assertThat(roundaboutExitAngle).isEqualTo(maneuver.getRoundaboutExitAngle()); |
| 177 | assertThat(CarIcon.APP_ICON).isEqualTo(maneuver.getIcon()); |
| 178 | } |
| 179 | |
| 180 | @Test |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 181 | public void createInstance_roundabout_with_angle_invalid_type() { |
| 182 | assertThrows( |
| 183 | IllegalArgumentException.class, |
| 184 | () -> |
Billy Lam | 994257a | 2022-01-14 16:42:06 -0800 | [diff] [blame] | 185 | new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_AND_EXIT_CCW) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 186 | .setRoundaboutExitAngle(1) |
| 187 | .setIcon(CarIcon.APP_ICON) |
| 188 | .build()); |
| 189 | assertThrows( |
| 190 | IllegalArgumentException.class, |
| 191 | () -> |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 192 | new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_CW) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 193 | .setRoundaboutExitNumber(1) |
| 194 | .setRoundaboutExitAngle(1) |
| 195 | .setIcon(CarIcon.APP_ICON) |
| 196 | .build()); |
| 197 | assertThrows( |
| 198 | IllegalArgumentException.class, |
| 199 | () -> |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 200 | new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 201 | .setRoundaboutExitNumber(1) |
| 202 | .setRoundaboutExitAngle(1) |
| 203 | .setIcon(CarIcon.APP_ICON) |
| 204 | .build()); |
| 205 | } |
| 206 | |
| 207 | @Test |
| 208 | public void createInstance_invalid_carIcon() { |
| 209 | Uri.Builder builder = new Uri.Builder(); |
| 210 | builder.scheme(ContentResolver.SCHEME_CONTENT); |
| 211 | builder.appendPath("foo/bar"); |
| 212 | Uri iconUri = builder.build(); |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 213 | CarIcon carIcon = new CarIcon.Builder(IconCompat.createWithContentUri(iconUri)).build(); |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 214 | |
| 215 | assertThrows( |
| 216 | IllegalArgumentException.class, |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 217 | () -> new Maneuver.Builder(TYPE_STRAIGHT).setIcon(carIcon).build()); |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | @Test |
| 221 | public void equals() { |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 222 | Maneuver maneuver = new Maneuver.Builder(TYPE_STRAIGHT).setIcon(CarIcon.APP_ICON).build(); |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 223 | |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 224 | assertThat(new Maneuver.Builder(TYPE_STRAIGHT).setIcon(CarIcon.APP_ICON).build()) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 225 | .isEqualTo(maneuver); |
| 226 | } |
| 227 | |
| 228 | @Test |
| 229 | public void notEquals_differentType() { |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 230 | Maneuver maneuver = new Maneuver.Builder(TYPE_DESTINATION_LEFT).setIcon( |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 231 | CarIcon.APP_ICON).build(); |
| 232 | |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 233 | assertThat(new Maneuver.Builder(TYPE_STRAIGHT).setIcon(CarIcon.APP_ICON).build()) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 234 | .isNotEqualTo(maneuver); |
| 235 | } |
| 236 | |
| 237 | @Test |
| 238 | public void notEquals_differentImage() { |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 239 | Maneuver maneuver = new Maneuver.Builder(TYPE_DESTINATION_LEFT).setIcon( |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 240 | CarIcon.APP_ICON).build(); |
| 241 | |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 242 | assertThat(new Maneuver.Builder(TYPE_DESTINATION_LEFT).setIcon(CarIcon.ALERT).build()) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 243 | .isNotEqualTo(maneuver); |
| 244 | } |
| 245 | |
| 246 | @Test |
| 247 | public void notEquals_differentRoundaboutExit() { |
| 248 | Maneuver maneuver = |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 249 | new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 250 | .setRoundaboutExitNumber(1) |
| 251 | .setIcon(CarIcon.APP_ICON) |
| 252 | .build(); |
| 253 | |
| 254 | assertThat( |
Jorge Pereira | 5dd252d | 2021-01-07 20:30:13 -0800 | [diff] [blame] | 255 | new Maneuver.Builder(TYPE_ROUNDABOUT_ENTER_AND_EXIT_CW) |
Ram Parameswaran | 619cc5f | 2020-11-03 21:07:41 -0800 | [diff] [blame] | 256 | .setRoundaboutExitNumber(2) |
| 257 | .setIcon(CarIcon.APP_ICON) |
| 258 | .build()) |
| 259 | .isNotEqualTo(maneuver); |
| 260 | } |
| 261 | } |