Skip to content

Commit

Permalink
Fix checkstyle issues and faulty test dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
vanitasvitae committed Jan 28, 2021
1 parent bc6c916 commit aa09316
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/**
*
* Copyright 2020 Paul Schaub
*
* 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 org.jivesoftware.smackx.avatar;

import java.util.Map;
Expand Down Expand Up @@ -27,7 +43,7 @@ private static class Tuple<A, B> {
private final A first;
private final B second;

public Tuple(A first, B second) {
Tuple(A first, B second) {
this.first = first;
this.second = second;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@
*/
package org.jivesoftware.smackx.avatar;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.jivesoftware.smack.test.util.SmackTestSuite;
import org.jivesoftware.smack.util.PacketParserUtils;
import org.jivesoftware.smack.util.stringencoder.Base64;
import org.jivesoftware.smack.xml.XmlPullParser;
import org.jivesoftware.smackx.avatar.element.DataExtension;
import org.jivesoftware.smackx.avatar.provider.DataProvider;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class DataExtensionTest extends SmackTestSuite {

Expand All @@ -38,11 +39,11 @@ public class DataExtensionTest extends SmackTestSuite {
public void checkDataExtensionParse() throws Exception {
byte[] data = Base64.decode("qANQR1DBwU4DX7jmYZnnfe32");
DataExtension dataExtension = new DataExtension(data);
Assert.assertEquals(dataExtensionExample, dataExtension.toXML().toString());
assertEquals(dataExtensionExample, dataExtension.toXML().toString());

XmlPullParser parser = PacketParserUtils.getParserFor(dataExtensionExample);
DataExtension dataExtensionFromProvider = new DataProvider().parse(parser);
Assert.assertEquals(Base64.encodeToString(data), Base64.encodeToString(dataExtensionFromProvider.getData()));
assertEquals(Base64.encodeToString(data), Base64.encodeToString(dataExtensionFromProvider.getData()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
package org.jivesoftware.smackx.avatar;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -27,8 +30,7 @@
import org.jivesoftware.smackx.avatar.element.MetadataExtension;
import org.jivesoftware.smackx.avatar.provider.MetadataProvider;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class MetadataExtensionTest {

Expand Down Expand Up @@ -99,23 +101,23 @@ public void checkMetadataExtensionParse() throws Exception {
infos.add(info);

MetadataExtension metadataExtension = new MetadataExtension(infos);
Assert.assertEquals(metadataExtensionExample, metadataExtension.toXML().toString());
assertEquals(metadataExtensionExample, metadataExtension.toXML().toString());

XmlPullParser parser = PacketParserUtils.getParserFor(metadataExtensionExample);
MetadataExtension metadataExtensionFromProvider = new MetadataProvider().parse(parser);

Assert.assertEquals(id, metadataExtensionFromProvider.getInfoElements().get(0).getId());
Assert.assertEquals(url, metadataExtensionFromProvider.getInfoElements().get(0).getUrl());
Assert.assertEquals(bytes, metadataExtensionFromProvider.getInfoElements().get(0).getBytes().intValue());
Assert.assertEquals(type, metadataExtensionFromProvider.getInfoElements().get(0).getType());
Assert.assertEquals(pixelsHeight, metadataExtensionFromProvider.getInfoElements().get(0).getHeight().intValue());
Assert.assertEquals(pixelsWidth, metadataExtensionFromProvider.getInfoElements().get(0).getWidth().intValue());
assertEquals(id, metadataExtensionFromProvider.getInfoElements().get(0).getId());
assertEquals(url, metadataExtensionFromProvider.getInfoElements().get(0).getUrl());
assertEquals(bytes, metadataExtensionFromProvider.getInfoElements().get(0).getBytes().intValue());
assertEquals(type, metadataExtensionFromProvider.getInfoElements().get(0).getType());
assertEquals(pixelsHeight, metadataExtensionFromProvider.getInfoElements().get(0).getHeight().intValue());
assertEquals(pixelsWidth, metadataExtensionFromProvider.getInfoElements().get(0).getWidth().intValue());
}

@Test
public void checkEmptyMetadataExtensionParse() throws Exception {
public void checkEmptyMetadataExtensionParse() {
MetadataExtension metadataExtension = new MetadataExtension(null);
Assert.assertEquals(emptyMetadataExtensionExample, metadataExtension.toXML().toString());
assertEquals(emptyMetadataExtensionExample, metadataExtension.toXML().toString());
}

@Test
Expand All @@ -127,26 +129,26 @@ public void checkSeveralInfosInMetadataExtension() throws Exception {
MetadataInfo info2 = metadataExtensionFromProvider.getInfoElements().get(1);
MetadataInfo info3 = metadataExtensionFromProvider.getInfoElements().get(2);

Assert.assertEquals("111f4b3c50d7b0df729d299bc6f8e9ef9066971f", info1.getId());
Assert.assertNull(info1.getUrl());
Assert.assertEquals(12345, info1.getBytes().intValue());
Assert.assertEquals("image/png", info1.getType());
Assert.assertEquals(64, info1.getHeight().intValue());
Assert.assertEquals(64, info1.getWidth().intValue());

Assert.assertEquals("e279f80c38f99c1e7e53e262b440993b2f7eea57", info2.getId());
Assert.assertEquals(new URL("http://avatars.example.org/happy.png"), info2.getUrl());
Assert.assertEquals(12345, info2.getBytes().intValue());
Assert.assertEquals("image/png", info2.getType());
Assert.assertEquals(64, info2.getHeight().intValue());
Assert.assertEquals(128, info2.getWidth().intValue());

Assert.assertEquals("357a8123a30844a3aa99861b6349264ba67a5694", info3.getId());
Assert.assertEquals(new URL("http://avatars.example.org/happy.gif"), info3.getUrl());
Assert.assertEquals(23456, info3.getBytes().intValue());
Assert.assertEquals("image/gif", info3.getType());
Assert.assertEquals(64, info3.getHeight().intValue());
Assert.assertEquals(64, info3.getWidth().intValue());
assertEquals("111f4b3c50d7b0df729d299bc6f8e9ef9066971f", info1.getId());
assertNull(info1.getUrl());
assertEquals(12345, info1.getBytes().intValue());
assertEquals("image/png", info1.getType());
assertEquals(64, info1.getHeight().intValue());
assertEquals(64, info1.getWidth().intValue());

assertEquals("e279f80c38f99c1e7e53e262b440993b2f7eea57", info2.getId());
assertEquals(new URL("http://avatars.example.org/happy.png"), info2.getUrl());
assertEquals(12345, info2.getBytes().intValue());
assertEquals("image/png", info2.getType());
assertEquals(64, info2.getHeight().intValue());
assertEquals(128, info2.getWidth().intValue());

assertEquals("357a8123a30844a3aa99861b6349264ba67a5694", info3.getId());
assertEquals(new URL("http://avatars.example.org/happy.gif"), info3.getUrl());
assertEquals(23456, info3.getBytes().intValue());
assertEquals("image/gif", info3.getType());
assertEquals(64, info3.getHeight().intValue());
assertEquals(64, info3.getWidth().intValue());
}

@Test
Expand All @@ -155,24 +157,24 @@ public void checkInfosAndPointersParse() throws Exception {
MetadataExtension metadataExtensionFromProvider = new MetadataProvider().parse(parser);

MetadataInfo info = metadataExtensionFromProvider.getInfoElements().get(0);
Assert.assertEquals("111f4b3c50d7b0df729d299bc6f8e9ef9066971f", info.getId());
Assert.assertNull(info.getUrl());
Assert.assertEquals(12345, info.getBytes().intValue());
Assert.assertEquals("image/png", info.getType());
Assert.assertEquals(64, info.getHeight().intValue());
Assert.assertEquals(64, info.getWidth().intValue());
assertEquals("111f4b3c50d7b0df729d299bc6f8e9ef9066971f", info.getId());
assertNull(info.getUrl());
assertEquals(12345, info.getBytes().intValue());
assertEquals("image/png", info.getType());
assertEquals(64, info.getHeight().intValue());
assertEquals(64, info.getWidth().intValue());

MetadataPointer pointer1 = metadataExtensionFromProvider.getPointerElements().get(0);
Map<String, Object> fields1 = pointer1.getFields();
Assert.assertEquals("http://example.com/virtualworlds", pointer1.getNamespace());
Assert.assertEquals("Ancapistan", fields1.get("game"));
Assert.assertEquals("Kropotkin", fields1.get("character"));
assertEquals("http://example.com/virtualworlds", pointer1.getNamespace());
assertEquals("Ancapistan", fields1.get("game"));
assertEquals("Kropotkin", fields1.get("character"));

MetadataPointer pointer2 = metadataExtensionFromProvider.getPointerElements().get(1);
Map<String, Object> fields2 = pointer2.getFields();
Assert.assertEquals("http://sample.com/game", pointer2.getNamespace());
Assert.assertEquals("hard", fields2.get("level"));
Assert.assertEquals("2", fields2.get("players"));
assertEquals("http://sample.com/game", pointer2.getNamespace());
assertEquals("hard", fields2.get("level"));
assertEquals("2", fields2.get("players"));
}

@Test
Expand Down Expand Up @@ -202,7 +204,7 @@ public void createMetadataExtensionWithInfoAndPointer() {
pointers.add(pointer2);

MetadataExtension metadataExtension = new MetadataExtension(infos, pointers);
Assert.assertEquals(metadataWithInfoAndPointers, metadataExtension.toXML().toString());
assertEquals(metadataWithInfoAndPointers, metadataExtension.toXML().toString());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand Down Expand Up @@ -95,7 +96,7 @@ public void onAvatarUpdateReceived(EntityBareJid user, MetadataExtension metadat

connection.connect().login();

Scanner input = new Scanner(System.in);
Scanner input = new Scanner(System.in, StandardCharsets.UTF_8.name());
while (true) {
String line = input.nextLine();

Expand All @@ -109,7 +110,7 @@ public void onAvatarUpdateReceived(EntityBareJid user, MetadataExtension metadat

private static void createDownloadDirectory(File avatarDownloadDirectory) throws IOException {
if (!avatarDownloadDirectory.mkdirs()) {
throw new IOException("Cannot create temp directory '" + avatarDownloadDirectory.getAbsolutePath() +"'");
throw new IOException("Cannot create temp directory '" + avatarDownloadDirectory.getAbsolutePath() + "'");
} else {
LOGGER.info("Created temporary avatar download directory '" + avatarDownloadDirectory.getAbsolutePath() + "'");
}
Expand Down

0 comments on commit aa09316

Please sign in to comment.