### Question:
CmakeServerExternalNativeJsonGenerator extends CmakeExternalNativeJsonGenerator { @VisibleForTesting static String getAndroidGradleFileLibFlags( @NonNull String fileName, @NonNull List<CompileCommand> compileCommands) { String flags = null; Path fileNamePath = Paths.get(fileName); for (CompileCommand compileCommand : compileCommands) { if (compileCommand.command == null || compileCommand.file == null) { continue; } if (fileNamePath.compareTo(Paths.get(compileCommand.file)) != 0) { continue; } flags = compileCommand.command.substring( compileCommand.command.indexOf(' ') + 1, compileCommand.command.indexOf(fileName)); break; } return flags; } CmakeServerExternalNativeJsonGenerator(
            @NonNull JsonGenerationVariantConfiguration config,
            @NonNull Set<String> configurationFailures,
            @NonNull AndroidBuilder androidBuilder,
            @NonNull File cmakeFolder,
            @NonNull GradleBuildVariant.Builder stats); @NonNull @Override String executeProcessAndGetOutput(@NonNull JsonGenerationAbiConfiguration abiConfig);  }### Answer:
@Test public void testParseValidFileFromCompileCommands() throws IOException { File compileCommandsTestFile = getCompileCommandsTestFile("compile_commands_valid_multiple_compilation.json"); List<CompileCommand> compileCommands = getCompilationDatabase(compileCommandsTestFile); String flags = CmakeServerExternalNativeJsonGenerator.getAndroidGradleFileLibFlags( "file.cc", compileCommands); assertThat(flags).isNotNull(); assertThat(flags) .isEqualTo("-Irelative -DSOMEDEF=\"With spaces, quotes and \\-es.\" -c -o file.o "); }
@Test public void testParseInvalidFileFromCompileCommands() throws IOException { File compileCommandsTestFile = getCompileCommandsTestFile("compile_commands_valid_multiple_compilation.json"); List<CompileCommand> compileCommands = getCompilationDatabase(compileCommandsTestFile); String flags = CmakeServerExternalNativeJsonGenerator.getAndroidGradleFileLibFlags( "invalid-file.cc", compileCommands); assertThat(flags).isNull(); }