blob: 1b754ca66958fd40b79e36a6e4bdfc243f8a6f5b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.config.server.tenant;
import com.google.common.testing.EqualsTester;
import com.yahoo.config.provision.TenantName;
import com.yahoo.vespa.config.server.TestComponentRegistry;
import com.yahoo.vespa.config.server.host.HostRegistry;
import org.junit.Before;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
/**
* @author Ulf Lilleengen
*/
public class TenantTest {
private final TestComponentRegistry componentRegistry = new TestComponentRegistry.Builder().build();
private Tenant t1;
private Tenant t2;
private Tenant t3;
private Tenant t4;
@Before
public void setupTenant() {
t1 = createTenant("foo");
t2 = createTenant("foo");
t3 = createTenant("bar");
t4 = createTenant("baz");
}
private Tenant createTenant(String name) {
TenantRepository tenantRepository = new TenantRepository(componentRegistry, new HostRegistry());
TenantName tenantName = TenantName.from(name);
tenantRepository.addTenant(tenantName);
return tenantRepository.getTenant(tenantName);
}
@Test
public void equals() {
new EqualsTester()
.addEqualityGroup(t1, t2)
.addEqualityGroup(t3)
.addEqualityGroup(t4)
.testEquals();
}
@Test
public void hashcode() {
assertThat(t1.hashCode(), is(t2.hashCode()));
assertThat(t1.hashCode(), is(not(t3.hashCode())));
assertThat(t1.hashCode(), is(not(t4.hashCode())));
}
}
|