src/test/java/de/blau/android/presets/PresetTest.java
/**
     * Test that we don't match a preset without the object and that we do with.
     */
Test that we don't match a preset without the object and that we do with.
Test that we don ' t match a preset without the object and that we do with .
@Test
    public void objectMatching() {
        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());
        Map<String, String> tags = new HashMap<>();
        tags.put("imaginary", "tag");
        PresetItem test = Preset.findBestMatch(presets, tags, null);
        assertNull(test);
        tags.clear();
        tags.put("imaginary2", "tag");
        test = Preset.findBestMatch(presets, tags, null);
        assertNotNull(test);
        assertEquals("Test Item 2", test.getName());
         match via key
        tags.clear();
        tags.put("highway", "tag");
        test = Preset.findBestMatch(presets, tags, null);
        assertNotNull(test);
        assertEquals("Test Item 3", test.getName());
         exception to top level key match
        tags.clear();
        tags.put("highway", "tag2");
        test = Preset.findBestMatch(presets, tags, null);
        assertNull(test);
    }
@ Test public void objectMatching ( ) { 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 ( ) ) ; Map < String , String > tags = new HashMap < > ( ) ; tags . put ( "imaginary" , "tag" ) ; PresetItem test = Preset . findBestMatch ( presets , tags , null ) ; assertNull ( test ) ; tags . clear ( ) ; tags . put ( "imaginary2" , "tag" ) ; test = Preset . findBestMatch ( presets , tags , null ) ; assertNotNull ( test ) ; assertEquals ( "Test Item 2" , test . getName ( ) ) ; tags . clear ( ) ; tags . put ( "highway" , "tag" ) ; test = Preset . findBestMatch ( presets , tags , null ) ; assertNotNull ( test ) ; assertEquals ( "Test Item 3" , test . getName ( ) ) ; tags . clear ( ) ; tags . put ( "highway" , "tag2" ) ; test = Preset . findBestMatch ( presets , tags , null ) ; assertNull ( test ) ; }
Test that we don't match a preset without the object and that we do with.
Test that we don ' t match a preset without the object and that we do with .
// // match via key // exception to top level key match