Browse Source

Fix checkstyle issues and faulty test dependencies

ramabit.avatar
Paul Schaub 2 months ago
parent
commit
fd27fad0b9
No known key found for this signature in database GPG Key ID: 62BEE9264BF17311
5 changed files with 72 additions and 52 deletions
  1. +1
    -1
      smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java
  2. +17
    -1
      smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/MemoryAvatarMetadataStore.java
  3. +5
    -4
      smack-extensions/src/test/java/org/jivesoftware/smackx/avatar/DataExtensionTest.java
  4. +46
    -44
      smack-extensions/src/test/java/org/jivesoftware/smackx/avatar/MetadataExtensionTest.java
  5. +3
    -2
      smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/Avatar.java

+ 1
- 1
smack-core/src/main/java/org/jivesoftware/smack/util/XmlStringBuilder.java View File

@@ -18,8 +18,8 @@ package org.jivesoftware.smack.util;

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;


+ 17
- 1
smack-extensions/src/main/java/org/jivesoftware/smackx/avatar/MemoryAvatarMetadataStore.java View File

@@ -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;
@@ -27,7 +43,7 @@ public class MemoryAvatarMetadataStore implements AvatarMetadataStore {
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;
}


+ 5
- 4
smack-extensions/src/test/java/org/jivesoftware/smackx/avatar/DataExtensionTest.java View File

@@ -16,6 +16,8 @@
*/
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;
@@ -23,8 +25,7 @@ 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 {

@@ -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()));
}

}

+ 46
- 44
smack-extensions/src/test/java/org/jivesoftware/smackx/avatar/MetadataExtensionTest.java View File

@@ -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;
@@ -27,8 +30,7 @@ import org.jivesoftware.smack.xml.XmlPullParser;
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 {

@@ -99,23 +101,23 @@ public class MetadataExtensionTest {
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
@@ -127,26 +129,26 @@ public class MetadataExtensionTest {
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
@@ -155,24 +157,24 @@ public class MetadataExtensionTest {
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
@@ -202,7 +204,7 @@ public class MetadataExtensionTest {
pointers.add(pointer2);

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

}

+ 3
- 2
smack-repl/src/main/java/org/igniterealtime/smack/smackrepl/Avatar.java View File

@@ -26,6 +26,7 @@ import java.io.FileOutputStream;
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;
@@ -95,7 +96,7 @@ public class Avatar {

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();

@@ -109,7 +110,7 @@ public class Avatar {

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() + "'");
}


Loading…
Cancel
Save