SchemaProvider { public Schema schema(String roadName, int version) { return Mono .justOrEmpty(store.get(roadName)) .switchIfEmpty(throwRoadDoesNotExist(roadName)) .map(Road::getSchemas) .flatMap(schemas -> Mono.justOrEmpty(schemas.get(version))) .switchIfEmpty(throwSchemaDoesNotExist(roadName, version)) .map(SchemaVersion::getSchema) .block(); }  Schema schema(String roadName, int version);  }
@Test(expected = IllegalArgumentException.class) public void roadDoesNotExist() { store.clear(); underTest.schema("road1", 1); }
@Test(expected = IllegalArgumentException.class) public void schemaDoesNotExist() { Road road = new Road(); road.setSchemas(Collections.emptyMap()); store.put("road1", road); underTest.schema("road1", 1); }
@Test public void getSchema() { Road road = new Road(); Schema schema = SchemaBuilder.builder().intType(); road.setSchemas(Collections.singletonMap(1, new SchemaVersion(schema, 1, false))); store.put("road1", road); Schema result = underTest.schema("road1", 1); assertThat(result, is(schema)); }