blob: f49e829e9914fa5acf407e81c87b05ff147d8e8c [file] [log] [blame]
Ray Milkeyd03eda02015-01-09 14:58:48 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.codec.impl;
17
18import org.onosproject.codec.CodecContext;
19import org.onosproject.codec.JsonCodec;
20
21import com.fasterxml.jackson.databind.ObjectMapper;
22
23/**
24 * Mock codec context for use in codec unit tests.
25 */
26public final class MockCodecContext implements CodecContext {
27
28 private ObjectMapper mapper = new ObjectMapper();
29 private CodecManager manager = new CodecManager();
30
Ray Milkeydb358082015-01-13 16:34:38 -080031 /**
32 * Constructs a new mock codec context.
33 */
Ray Milkeyd03eda02015-01-09 14:58:48 -080034 public MockCodecContext() {
35 manager.activate();
36 }
37
38 @Override
39 public ObjectMapper mapper() {
40 return mapper;
41 }
42
43 @Override
44 @SuppressWarnings("unchecked")
45 public <T> JsonCodec<T> codec(Class<T> entityClass) {
46 return manager.getCodec(entityClass);
47 }
48
49 @Override
50 public <T> T get(Class<T> serviceClass) {
51 return null;
52 }
53
54}