Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add common generator tests for the iterable map and normal map
  • Loading branch information
chingor13 committed Dec 28, 2018
commit 485286ea8df75476172d0c25a1c8afb59c14e454
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.api.client.json.gson;

import com.google.api.client.json.JsonGenerator;
import com.google.api.client.test.json.AbstractJsonGeneratorTest;
import java.io.IOException;
import java.io.Writer;

public class GsonGeneratorTest extends AbstractJsonGeneratorTest {

private static final GsonFactory FACTORY = new GsonFactory();

@Override
protected JsonGenerator newGenerator(Writer writer) throws IOException {
return FACTORY.createJsonGenerator(writer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.api.client.json.jackson;

import com.google.api.client.json.JsonGenerator;
import com.google.api.client.test.json.AbstractJsonGeneratorTest;
import java.io.IOException;
import java.io.Writer;

public class JacksonGeneratorTest extends AbstractJsonGeneratorTest {

private static final JacksonFactory FACTORY = new JacksonFactory();

@Override
protected JsonGenerator newGenerator(Writer writer) throws IOException {
return FACTORY.createJsonGenerator(writer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.api.client.json.jackson2;

import com.google.api.client.json.JsonGenerator;
import com.google.api.client.test.json.AbstractJsonGeneratorTest;
import java.io.IOException;
import java.io.Writer;

public class JacksonGeneratorTest extends AbstractJsonGeneratorTest {

private static final JacksonFactory FACTORY = new JacksonFactory();

@Override
protected JsonGenerator newGenerator(Writer writer) throws IOException {
return FACTORY.createJsonGenerator(writer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (c) 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package com.google.api.client.test.json;

import com.google.api.client.json.JsonGenerator;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import junit.framework.TestCase;

public abstract class AbstractJsonGeneratorTest extends TestCase {

protected abstract JsonGenerator newGenerator(Writer writer) throws IOException;

class IterableMap extends HashMap<String, String> implements Iterable<Map.Entry<String, String>> {
@Override
public Iterator<Entry<String, String>> iterator() {
return entrySet().iterator();
}
}

public void testSerialize_simpleMap() throws Exception {
StringWriter writer = new StringWriter();
JsonGenerator generator = newGenerator(writer);

Map m = new HashMap<String, String>();
m.put("a", "b");
m.put("c", "d");

generator.serialize(m);
generator.close();
assertEquals("{\"a\":\"b\",\"c\":\"d\"}", writer.toString());
}

public void testSerialize_iterableMap() throws Exception {
StringWriter writer = new StringWriter();
JsonGenerator generator = newGenerator(writer);

Map m = new IterableMap();
m.put("a", "b");
m.put("c", "d");

generator.serialize(m);
generator.close();
assertEquals("{\"a\":\"b\",\"c\":\"d\"}", writer.toString());
}
}