Skip to content

Commit

Permalink
Fix missing path separator in image path
Browse files Browse the repository at this point in the history
At some point in time it seems as if the path separator started missing
from the end of the directory path, this adds it back and adds a test
that the generated paths actually exist.
  • Loading branch information
simonpoole committed Sep 3, 2023
1 parent 5170bfa commit 757e4b9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@
import de.blau.android.prefs.Preferences;
import de.blau.android.prefs.PresetLoader;
import de.blau.android.presets.Preset;
import de.blau.android.presets.PresetComboField;
import de.blau.android.presets.PresetItem;
import de.blau.android.util.StringWithDescription;
import de.blau.android.util.StringWithDescriptionAndIcon;

@RunWith(AndroidJUnit4.class)
@LargeTest
Expand Down Expand Up @@ -149,4 +153,28 @@ public void bicycleParking() {
assertNotNull(n);
assertTrue(n.hasTag("bicycle_parking", "handlebar_holder"));
}

/**
* Check that the images can actually be opened
*/
@Test
public void checkImage() {
Preset[] presets = App.getCurrentPresets(main);
for (Preset p:presets) {
PresetItem item =p.getItemByName("Parking", null);
if (item != null) {
PresetComboField combo = (PresetComboField) item.getField("bicycle_parking");
for (StringWithDescription value: combo.getValues()) {
if ("stands".equals(value.getValue()) && value instanceof StringWithDescriptionAndIcon) {
String imagePath = ((StringWithDescriptionAndIcon) value).getImagePath();
if (imagePath != null) {
assertTrue(new File(imagePath).exists());
return;
}
}
}
}
}
fail("preset not found");
}
}
2 changes: 1 addition & 1 deletion src/main/java/de/blau/android/presets/PresetParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ public void endElement(String uri, String localName, String name) throws SAXExce
*/
@NonNull
private String getImagePath(@NonNull Preset preset, @NonNull String imagePath) {
return preset.isDefault() ? imagePath : preset.getDirectory().toString() + imagePath;
return preset.isDefault() ? imagePath : preset.getDirectory().getAbsolutePath() + "/" + imagePath;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ public class ComboImageLoader extends ImageLoader {

private static final long serialVersionUID = 1L;

private List<Value> values; // NOSONAR
private String key;
private final List<Value> values; // NOSONAR
private final String key;

/**
* Construct a new loader
*
* @param key the key
* @param values a list of values
*/
ComboImageLoader(String key, @NonNull List<Value> values) {
ComboImageLoader(@NonNull String key, @NonNull List<Value> values) {
this.key = key;
this.values = values;
}
Expand Down

0 comments on commit 757e4b9

Please sign in to comment.