### Question:
ApplicationSpecificationAdapter { public static Set<ProgramId> getProgramIds(ApplicationId appId, JsonReader reader) throws IOException { Set<ProgramId> result = new HashSet<>(); reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { String name = reader.nextName(); switch (name) { case "mapReduces": case "sparks": case "workflows": case "services": case "workers": reader.beginObject(); while (reader.peek() != JsonToken.END_OBJECT) { String programName = reader.nextName(); ProgramType programType = ProgramType.valueOf(name.substring(0, name.length() - 1).toUpperCase()); result.add(appId.program(programType, programName)); reader.skipValue(); } reader.endObject(); break; case "name": String appName = reader.nextString(); if (!appId.getApplication().equals(appName)) { throw new IllegalArgumentException( String.format("Application name in the specification is '%s' and it doesn't " + "match with the provided application id '%s'", appName, appId.getApplication())); } break; default: reader.skipValue(); } } reader.endObject(); return result; } private  ApplicationSpecificationAdapter(Gson gson); static ApplicationSpecificationAdapter create(); static GsonBuilder addTypeAdapters(GsonBuilder builder); static Set<ProgramId> getProgramIds(ApplicationId appId, JsonReader reader); String toJson(ApplicationSpecification appSpec); void toJson(ApplicationSpecification appSpec, Appendable appendable); ApplicationSpecification fromJson(String json); ApplicationSpecification fromJson(Reader reader);  }### Answer:
@Test public void testGetProgramIds() throws IOException { ApplicationSpecification appSpec = Specifications.from(new AllProgramsApp()); ApplicationId appId = NamespaceId.DEFAULT.app(appSpec.getName()); Set<ProgramId> expectedIds = new HashSet<>(); for (ProgramType programType : ProgramType.values()) { appSpec.getProgramsByType(programType).stream() .map(name -> appId.program(io.cdap.cdap.proto.ProgramType.valueOf(programType.name()), name)) .forEach(expectedIds::add); } String json = ApplicationSpecificationAdapter.create().toJson(appSpec); try (JsonReader reader = new JsonReader(new StringReader(json))) { Set<ProgramId> programIds = ApplicationSpecificationAdapter.getProgramIds(appId, reader); Assert.assertEquals(expectedIds, programIds); } }