src/test/java/de/blau/android/presets/PresetTest.java
/**
     * Test that we can find items with the same name that differ in which region they apply to
     */
Test that we can find items with the same name that differ in which region they apply to
Test that we can find items with the same name that differ in which region they apply to
@Test
    public void sameName() {
        try (AdvancedPrefDatabase db = new AdvancedPrefDatabase(ApplicationProvider.getApplicationContext())) {
            File preset = JavaResources.copyFileFromResources(ApplicationProvider.getApplicationContext(), "test-preset.xml", null, "/");
            String presetId = java.util.UUID.randomUUID().toString();
            db.addPreset(presetId, "Test preset", "", true);
            File presetDir = db.getPresetDirectory(presetId);
            presetDir.mkdir();
            Uri inputUri = Uri.parse(preset.toURI().toString());
            ContentResolver contentResolver = ApplicationProvider.getApplicationContext().getContentResolver();
            ShadowContentResolver shadowContentResolver = shadowOf(contentResolver);
            shadowContentResolver.registerInputStream(inputUri, new FileInputStream(preset));
            PresetLoader.load(ApplicationProvider.getApplicationContext(), inputUri, presetDir, "test-preset.xml");
            App.resetPresets();
        } catch (Exception ex) {
            fail(ex.getMessage());
        }
        presets = App.getCurrentPresets(ApplicationProvider.getApplicationContext());
        Preset testPreset = null;
        for (Preset p : presets) {
            if ("Testing preset".equals(p.getShortDescription())) {
                testPreset = p;
                break;
            }
        }
        assertNotNull(testPreset);
        PresetItem testItem = testPreset.getItemByName("Test Same Name", "CH");
        assertNotNull(testItem);
        assertTrue(testItem.hasKeyValue("samething", "is in CH"));
        PresetElementPath testPath = testItem.getPath(testPreset.getRootGroup());
        assertNotNull(testPath);
        PresetItem testItemByPath = (PresetItem) Preset.getElementByPath(testPreset.getRootGroup(), testPath, "CH", false);
        assertEquals(testItem, testItemByPath);
        testItem = testPreset.getItemByName("Test Same Name", "DE");
        assertNotNull(testItem);
        assertTrue(testItem.hasKeyValue("samething", "not in CH"));
        testPath = testItem.getPath(testPreset.getRootGroup());
        assertNotNull(testPath);
        testItemByPath = (PresetItem) Preset.getElementByPath(testPreset.getRootGroup(), testPath, "DE", false);
        assertEquals(testItem, testItemByPath);
    }
@ Test public void sameName ( ) { try ( AdvancedPrefDatabase db = new AdvancedPrefDatabase ( ApplicationProvider . getApplicationContext ( ) ) ) { File preset = JavaResources . copyFileFromResources ( ApplicationProvider . getApplicationContext ( ) , "test-preset.xml" , null , "/" ) ; String presetId = java . util . UUID . randomUUID ( ) . toString ( ) ; db . addPreset ( presetId , "Test preset" , "" , true ) ; File presetDir = db . getPresetDirectory ( presetId ) ; presetDir . mkdir ( ) ; Uri inputUri = Uri . parse ( preset . toURI ( ) . toString ( ) ) ; ContentResolver contentResolver = ApplicationProvider . getApplicationContext ( ) . getContentResolver ( ) ; ShadowContentResolver shadowContentResolver = shadowOf ( contentResolver ) ; shadowContentResolver . registerInputStream ( inputUri , new FileInputStream ( preset ) ) ; PresetLoader . load ( ApplicationProvider . getApplicationContext ( ) , inputUri , presetDir , "test-preset.xml" ) ; App . resetPresets ( ) ; } catch ( Exception ex ) { fail ( ex . getMessage ( ) ) ; } presets = App . getCurrentPresets ( ApplicationProvider . getApplicationContext ( ) ) ; Preset testPreset = null ; for ( Preset p : presets ) { if ( "Testing preset" . equals ( p . getShortDescription ( ) ) ) { testPreset = p ; break ; } } assertNotNull ( testPreset ) ; PresetItem testItem = testPreset . getItemByName ( "Test Same Name" , "CH" ) ; assertNotNull ( testItem ) ; assertTrue ( testItem . hasKeyValue ( "samething" , "is in CH" ) ) ; PresetElementPath testPath = testItem . getPath ( testPreset . getRootGroup ( ) ) ; assertNotNull ( testPath ) ; PresetItem testItemByPath = ( PresetItem ) Preset . getElementByPath ( testPreset . getRootGroup ( ) , testPath , "CH" , false ) ; assertEquals ( testItem , testItemByPath ) ; testItem = testPreset . getItemByName ( "Test Same Name" , "DE" ) ; assertNotNull ( testItem ) ; assertTrue ( testItem . hasKeyValue ( "samething" , "not in CH" ) ) ; testPath = testItem . getPath ( testPreset . getRootGroup ( ) ) ; assertNotNull ( testPath ) ; testItemByPath = ( PresetItem ) Preset . getElementByPath ( testPreset . getRootGroup ( ) , testPath , "DE" , false ) ; assertEquals ( testItem , testItemByPath ) ; }
Test that we can find items with the same name that differ in which region they apply to
Test that we can find items with the same name that differ in which region they apply to
//