### Question:
PeerMetadataHandler extends StubMapping implements InternalStubMapping { @Override public boolean matches(Frame frame) { if (frame.message instanceof Query) { Query query = (Query) frame.message; String queryStr = query.query; for (Pattern pattern : queryPatterns) { if (pattern.matcher(queryStr).matches()) { return true; } } } return false; } PeerMetadataHandler();  PeerMetadataHandler(boolean supportsV2); @Override boolean matches(Frame frame); @Override List<Action> getActions(AbstractNode node, Frame frame);  }### Answer:
@Test public void shouldMatchLocalAndPeersQueries() { assertThat(handler.matches(node0, queryFrame("SELECT * FROM system.peers"))).isTrue(); assertThat(handler.matches(node0, queryFrame(" select * from system.peers ; "))).isTrue(); assertThat(handler.matches(node0, queryFrame("SELECT * FROM system.peers_v2"))).isTrue(); assertThat(handler.matches(node0, queryFrame(" select * from system.peers_v2 ; "))) .isTrue(); assertThat(handler.matches(node0, queryFrame("SELECT cluster_name FROM system.local"))) .isTrue(); assertThat(handler.matches(node0, queryFrame(" select cluster_name from system.local ; "))) .isTrue(); assertThat(handler.matches(node0, queryFrame("SELECT * FROM system.local WHERE key='local'"))) .isTrue(); assertThat( handler.matches( node0, queryFrame(" select * from system.local where key = 'local' ; "))) .isTrue(); assertThat( handler.matches(node0, queryFrame("SELECT * FROM system.peers WHERE peer='127.0.3.2'"))) .isTrue(); assertThat( handler.matches( node0, queryFrame(" select * from system.peers where peer = '127.0.3.2' ; "))) .isTrue(); assertThat( handler.matches(node0, queryFrame("SELECT * FROM system.peers WHERE peer='17.0.3.7'"))) .isTrue(); assertThat( handler.matches( node0, queryFrame(" select * from system.peers where peer = '17.0.3.7' ; "))) .isTrue(); assertThat(handler.matches(node0, queryFrame("SELECT * FROM system.peers WHERE peer=:address"))) .isTrue(); assertThat( handler.matches( node0, queryFrame(" select * from system.peers where peer = :address ; "))) .isTrue(); assertThat( handler.matches( node0, queryFrame( "SELECT * FROM system.peers_v2 WHERE peer=:address AND peer_port=:port"))) .isFalse(); assertThat( handler.matches( node0, queryFrame( " select * from system.peers_v2 where peer = :address and peer_port = :port ; "))) .isFalse(); assertThat( handlerV2.matches( node0, queryFrame( "SELECT * FROM system.peers_v2 WHERE peer=:address AND peer_port=:port"))) .isTrue(); assertThat( handlerV2.matches( node0, queryFrame( " select * from system.peers_v2 where peer = :address and peer_port = :port ; "))) .isTrue(); }
@Test public void shouldNotMatch() { assertThat(handler.matches(node0, queryFrame("SELECT foo FROM bar"))).isFalse(); assertThat(handler.matches(node0, FrameUtils.wrapRequest(new Startup()))).isFalse(); assertThat(handler.matches(node0, FrameUtils.wrapRequest(Options.INSTANCE))).isFalse(); }