/** * Creates a "reader" which is able to deserialize binary data into a immutables instance (using GSON type adapter). */ public static <T> Decoder<T> decoderFor(final Class<T> type, final TypeAdapter<T> adapter) { checkNotNull(type, "type"); checkNotNull(adapter, "adapter"); return new Decoder<T>() { @Override public T decode(BsonReader reader, DecoderContext decoderContext) { if (!(reader instanceof AbstractBsonReader)) { throw new UnsupportedOperationException(String.format("Only readers of type %s supported. Yours is %s", AbstractBsonReader.class.getName(), reader.getClass().getName())); } try { return adapter.read(new org.immutables.mongo.repository.internal.BsonReader((AbstractBsonReader) reader)); } catch (IOException e) { throw new RuntimeException(String.format("Couldn't encode %s", type), e); } } }; }
@SuppressWarnings({"rawtypes", "unchecked"}) @Before public void setUp() throws Exception { interceptor = new MongoDBMethodInterceptor(); Config.Plugin.MongoDB.TRACE_PARAM = true; when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:27017"); BsonDocument document = new BsonDocument(); document.append("name", new BsonString("by")); MongoNamespace mongoNamespace = new MongoNamespace("test.user"); Decoder decoder = PowerMockito.mock(Decoder.class); FindOperation findOperation = new FindOperation(mongoNamespace, decoder); findOperation.filter(document); arguments = new Object[] {findOperation}; argumentTypes = new Class[] {findOperation.getClass()}; }