Skip to content

Commit

Permalink
eclipse-ditto#985: Add test for new credential types
Browse files Browse the repository at this point in the history
Signed-off-by: Vadim Guenther <vadim.guenther@bosch.io>
  • Loading branch information
VadimGue committed Mar 5, 2021
1 parent bdf16ca commit e2af8c3
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ public Builder toBuilder() {
return new Builder(username, password);
}

/**
* Create a new builder initialized with fields of this object.
*
* @return a new builder.
*/
public static Builder newBuilder(final String username, final String password) {
return new Builder(username, password);
}

/**
* Builder of {@code UserPasswordCredentials}.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.model.connectivity;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;

/**
* Tests {@link org.eclipse.ditto.model.connectivity.KeyPairCredentials}.
*/
public final class KeyPairCredentialsTest {

@Test
public void testHashCodeAndEquals() {
EqualsVerifier.forClass(KeyPairCredentials.class).verify();
}

@Test
public void assertImmutability() {
assertInstancesOf(KeyPairCredentials.class, areImmutable());
}

@Test
public void testJsonSerialization() {
final Credentials original = KeyPairCredentials.newBuilder("bad public key", "bad private key")
.build();
final Credentials deserialized = Credentials.fromJson(original.toJson());
assertThat(deserialized).isEqualTo(original);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.model.connectivity;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mutabilitydetector.unittesting.MutabilityAssert.assertInstancesOf;
import static org.mutabilitydetector.unittesting.MutabilityMatchers.areImmutable;

import org.junit.Test;

import nl.jqno.equalsverifier.EqualsVerifier;

/**
* Tests {@link org.eclipse.ditto.model.connectivity.UserPasswordCredentials}.
*/
public final class UsernamePasswordCredentialsTest {

@Test
public void testHashCodeAndEquals() {
EqualsVerifier.forClass(UserPasswordCredentials.class).verify();
}

@Test
public void assertImmutability() {
assertInstancesOf(UserPasswordCredentials.class, areImmutable());
}

@Test
public void testJsonSerialization() {
final Credentials original = UserPasswordCredentials.newBuilder("username", "password")
.build();
final Credentials deserialized = Credentials.fromJson(original.toJson());
assertThat(deserialized).isEqualTo(original);
}
}

0 comments on commit e2af8c3

Please sign in to comment.