SearchItemHandler extends MenuHandler { @Override public boolean onCreate(@NotNull ViewEditor editor, @Nullable NlComponent parent, @NotNull NlComponent newChild, @NotNull InsertType type) { if (!super.onCreate(editor, parent, newChild, type)) { return false; } if (!type.equals(InsertType.CREATE)) { return true; } NlWriteCommandActionUtil.run(newChild, "", () -> { String value = editor.getMinSdkVersion().getApiLevel() < 11 ? "android.support.v7.widget.SearchView" : "android.widget.SearchView"; String namespace = editor.moduleDependsOnAppCompat() ? AUTO_URI : ANDROID_URI; newChild.setAttribute(namespace, "actionViewClass", value); }); return true; }  @Override boolean onCreate(@NotNull ViewEditor editor,
                          @Nullable NlComponent parent,
                          @NotNull NlComponent newChild,
                          @NotNull InsertType type); @NotNull @Override Icon getIcon(@NotNull NlComponent component);  }
@Test public void onCreateApiLevelIs10() { when(myEditor.getMinSdkVersion()).thenReturn(new AndroidVersion(10, null)); myHandler.onCreate(myEditor, null, newChild, InsertType.CREATE); Mockito.verify(newChild).setAttribute(ANDROID_URI, "actionViewClass", "android.support.v7.widget.SearchView"); }
@Test public void onCreateApiLevelIs11() { when(myEditor.getMinSdkVersion()).thenReturn(new AndroidVersion(11, null)); myHandler.onCreate(myEditor, null, newChild, InsertType.CREATE); Mockito.verify(newChild).setAttribute(ANDROID_URI, "actionViewClass", "android.widget.SearchView"); }
@Test public void onCreateWithAppCompat() { when(myEditor.getMinSdkVersion()).thenReturn(new AndroidVersion(27, null)); when(myEditor.moduleDependsOnAppCompat()).thenReturn(true); myHandler.onCreate(myEditor, null, newChild, InsertType.CREATE); Mockito.verify(newChild).setAttribute(AUTO_URI, "actionViewClass", "android.widget.SearchView"); }