minor test fixes

Reverting arguments in assertEquals where constant was placed on
the "actual" place. Replacing assertEquals with assertFalse, assertTrue
and assertNull where applicable.

Fixes gh-735
This commit is contained in:
sopov.ivan 2014-04-25 17:50:59 +04:00 committed by Dave Syer
parent 72ff1dd175
commit 174b654faf
13 changed files with 56 additions and 62 deletions

View File

@ -117,7 +117,7 @@ public class CrshAutoConfigurationTests {
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().getProperty("crash.ssh.port"), "3333"); assertEquals("3333", lifeCycle.getConfig().getProperty("crash.ssh.port"));
} }
@Test @Test
@ -132,8 +132,7 @@ public class CrshAutoConfigurationTests {
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().getProperty("crash.ssh.keypath"), assertEquals("~/.ssh/id.pem", lifeCycle.getConfig().getProperty("crash.ssh.keypath"));
"~/.ssh/id.pem");
} }
@Test @Test
@ -194,7 +193,7 @@ public class CrshAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().get("crash.auth"), "simple"); assertEquals("simple", lifeCycle.getConfig().get("crash.auth"));
} }
@Test @Test
@ -210,9 +209,8 @@ public class CrshAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().get("crash.auth"), "jaas"); assertEquals("jaas", lifeCycle.getConfig().get("crash.auth"));
assertEquals(lifeCycle.getConfig().get("crash.auth.jaas.domain"), assertEquals("my-test-domain", lifeCycle.getConfig().get("crash.auth.jaas.domain"));
"my-test-domain");
} }
@Test @Test
@ -228,8 +226,8 @@ public class CrshAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().get("crash.auth"), "key"); assertEquals("key", lifeCycle.getConfig().get("crash.auth"));
assertEquals(lifeCycle.getConfig().get("crash.auth.key.path"), "~/test.pem"); assertEquals("~/test.pem", lifeCycle.getConfig().get("crash.auth.key.path"));
} }
@Test @Test
@ -246,7 +244,7 @@ public class CrshAutoConfigurationTests {
this.context.refresh(); this.context.refresh();
PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class); PluginLifeCycle lifeCycle = this.context.getBean(PluginLifeCycle.class);
assertEquals(lifeCycle.getConfig().get("crash.auth"), "simple"); assertEquals("simple", lifeCycle.getConfig().get("crash.auth"));
AuthenticationPlugin<String> authenticationPlugin = null; AuthenticationPlugin<String> authenticationPlugin = null;
String authentication = lifeCycle.getConfig().getProperty("crash.auth"); String authentication = lifeCycle.getConfig().getProperty("crash.auth");
@ -260,8 +258,7 @@ public class CrshAutoConfigurationTests {
} }
assertNotNull(authenticationPlugin); assertNotNull(authenticationPlugin);
assertTrue(authenticationPlugin.authenticate("user", "password")); assertTrue(authenticationPlugin.authenticate("user", "password"));
assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), "password"));
"password"));
} }
@Test @Test
@ -287,11 +284,9 @@ public class CrshAutoConfigurationTests {
break; break;
} }
} }
assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME, assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME, SecurityConfiguration.PASSWORD));
SecurityConfiguration.PASSWORD));
assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), SecurityConfiguration.PASSWORD));
SecurityConfiguration.PASSWORD));
} }
@Test @Test
@ -316,11 +311,9 @@ public class CrshAutoConfigurationTests {
break; break;
} }
} }
assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME, assertTrue(authenticationPlugin.authenticate(SecurityConfiguration.USERNAME, SecurityConfiguration.PASSWORD));
SecurityConfiguration.PASSWORD));
assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), assertFalse(authenticationPlugin.authenticate(UUID.randomUUID().toString(), SecurityConfiguration.PASSWORD));
SecurityConfiguration.PASSWORD));
} }
@Configuration @Configuration

View File

@ -58,7 +58,7 @@ public class RabbitAutoconfigurationTests {
assertNotNull(connectionFactory); assertNotNull(connectionFactory);
assertNotNull(amqpAdmin); assertNotNull(amqpAdmin);
assertEquals(rabbitTemplate.getConnectionFactory(), connectionFactory); assertEquals(rabbitTemplate.getConnectionFactory(), connectionFactory);
assertEquals(connectionFactory.getHost(), "localhost"); assertEquals("localhost", connectionFactory.getHost());
} }
@Test @Test
@ -72,9 +72,9 @@ public class RabbitAutoconfigurationTests {
this.context.refresh(); this.context.refresh();
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertEquals(connectionFactory.getHost(), "remote-server"); assertEquals("remote-server", connectionFactory.getHost());
assertEquals(connectionFactory.getPort(), 9000); assertEquals(9000, connectionFactory.getPort());
assertEquals(connectionFactory.getVirtualHost(), "/vhost"); assertEquals("/vhost", connectionFactory.getVirtualHost());
} }
@Test @Test
@ -86,7 +86,7 @@ public class RabbitAutoconfigurationTests {
this.context.refresh(); this.context.refresh();
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertEquals(connectionFactory.getVirtualHost(), "/"); assertEquals("/", connectionFactory.getVirtualHost());
} }
@Test @Test
@ -98,7 +98,7 @@ public class RabbitAutoconfigurationTests {
this.context.refresh(); this.context.refresh();
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertEquals(connectionFactory.getVirtualHost(), "/foo"); assertEquals("/foo", connectionFactory.getVirtualHost());
} }
@Test @Test
@ -110,7 +110,7 @@ public class RabbitAutoconfigurationTests {
this.context.refresh(); this.context.refresh();
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertEquals(connectionFactory.getVirtualHost(), "/"); assertEquals("/", connectionFactory.getVirtualHost());
} }
@Test @Test
@ -122,8 +122,8 @@ public class RabbitAutoconfigurationTests {
CachingConnectionFactory connectionFactory = this.context CachingConnectionFactory connectionFactory = this.context
.getBean(CachingConnectionFactory.class); .getBean(CachingConnectionFactory.class);
assertEquals(rabbitTemplate.getConnectionFactory(), connectionFactory); assertEquals(rabbitTemplate.getConnectionFactory(), connectionFactory);
assertEquals(connectionFactory.getHost(), "otherserver"); assertEquals("otherserver", connectionFactory.getHost());
assertEquals(connectionFactory.getPort(), 8001); assertEquals(8001, connectionFactory.getPort());
} }
@Test @Test

View File

@ -19,6 +19,7 @@ package org.springframework.boot.autoconfigure.amqp;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/** /**
* Tests for {@link RabbitProperties}. * Tests for {@link RabbitProperties}.
@ -45,7 +46,7 @@ public class RabbitPropertiesTests {
@Test @Test
public void addressesDoubleValued() { public void addressesDoubleValued() {
this.properties.setAddresses("myhost:9999,otherhost:1111"); this.properties.setAddresses("myhost:9999,otherhost:1111");
assertEquals(null, this.properties.getHost()); assertNull(this.properties.getHost());
assertEquals(9999, this.properties.getPort()); assertEquals(9999, this.properties.getPort());
} }

View File

@ -26,6 +26,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link CommonsDataSourceConfiguration}. * Tests for {@link CommonsDataSourceConfiguration}.
@ -62,9 +63,9 @@ public class CommonsDataSourceConfigurationTests {
this.context.refresh(); this.context.refresh();
BasicDataSource ds = this.context.getBean(BasicDataSource.class); BasicDataSource ds = this.context.getBean(BasicDataSource.class);
assertEquals("jdbc:foo//bar/spam", ds.getUrl()); assertEquals("jdbc:foo//bar/spam", ds.getUrl());
assertEquals(true, ds.getTestWhileIdle()); assertTrue(ds.getTestWhileIdle());
assertEquals(true, ds.getTestOnBorrow()); assertTrue(ds.getTestOnBorrow());
assertEquals(true, ds.getTestOnReturn()); assertTrue(ds.getTestOnReturn());
assertEquals(10000, ds.getTimeBetweenEvictionRunsMillis()); assertEquals(10000, ds.getTimeBetweenEvictionRunsMillis());
assertEquals(12345, ds.getMinEvictableIdleTimeMillis()); assertEquals(12345, ds.getMinEvictableIdleTimeMillis());
assertEquals(1234, ds.getMaxWait()); assertEquals(1234, ds.getMaxWait());

View File

@ -33,6 +33,7 @@ import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
/** /**
@ -80,9 +81,9 @@ public class TomcatDataSourceConfigurationTests {
org.apache.tomcat.jdbc.pool.DataSource ds = this.context org.apache.tomcat.jdbc.pool.DataSource ds = this.context
.getBean(org.apache.tomcat.jdbc.pool.DataSource.class); .getBean(org.apache.tomcat.jdbc.pool.DataSource.class);
assertEquals("jdbc:foo//bar/spam", ds.getUrl()); assertEquals("jdbc:foo//bar/spam", ds.getUrl());
assertEquals(true, ds.isTestWhileIdle()); assertTrue(ds.isTestWhileIdle());
assertEquals(true, ds.isTestOnBorrow()); assertTrue(ds.isTestOnBorrow());
assertEquals(true, ds.isTestOnReturn()); assertTrue(ds.isTestOnReturn());
assertEquals(10000, ds.getTimeBetweenEvictionRunsMillis()); assertEquals(10000, ds.getTimeBetweenEvictionRunsMillis());
assertEquals(12345, ds.getMinEvictableIdleTimeMillis()); assertEquals(12345, ds.getMinEvictableIdleTimeMillis());
assertEquals(1234, ds.getMaxWait()); assertEquals(1234, ds.getMaxWait());

View File

@ -55,10 +55,7 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(connectionFactory); assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory); assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals( assertEquals("vm://localhost", ((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory())
.getBrokerURL(),
"vm://localhost");
} }
@Test @Test
@ -144,10 +141,8 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(connectionFactory); assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory); assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals( assertEquals("tcp://localhost:61616",
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()) ((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
.getBrokerURL(),
"tcp://localhost:61616");
} }
@Test @Test
@ -165,10 +160,8 @@ public class JmsTemplateAutoConfigurationTests {
assertNotNull(jmsTemplate); assertNotNull(jmsTemplate);
assertNotNull(connectionFactory); assertNotNull(connectionFactory);
assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory); assertEquals(jmsTemplate.getConnectionFactory(), connectionFactory);
assertEquals( assertEquals("tcp://remote-host:10000",
((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()) ((ActiveMQConnectionFactory) jmsTemplate.getConnectionFactory()).getBrokerURL());
.getBrokerURL(),
"tcp://remote-host:10000");
} }
@Test @Test

View File

@ -162,14 +162,14 @@ public class MultipartAutoConfigurationTests {
this.context.register(ContainerWithNoMultipartTomcat.class, this.context.register(ContainerWithNoMultipartTomcat.class,
BaseConfiguration.class); BaseConfiguration.class);
this.context.refresh(); this.context.refresh();
assertEquals(this.context.getBeansOfType(MultipartConfigElement.class).size(), 0); assertEquals(0, this.context.getBeansOfType(MultipartConfigElement.class).size());
} }
private void verifyServletWorks() { private void verifyServletWorks() {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
assertEquals(restTemplate.getForObject("http://localhost:" assertEquals("Hello", restTemplate.getForObject("http://localhost:"
+ this.context.getEmbeddedServletContainer().getPort() + "/", + this.context.getEmbeddedServletContainer().getPort() + "/",
String.class), "Hello"); String.class));
} }
@Configuration @Configuration

View File

@ -31,6 +31,7 @@ import org.springframework.boot.cli.command.core.HintCommand;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willThrow; import static org.mockito.BDDMockito.willThrow;
@ -124,7 +125,7 @@ public class CommandRunnerTests {
verify(this.regularCommand).run("--", "--debug", "bar"); verify(this.regularCommand).run("--", "--debug", "bar");
// When handled by the command itself it shouldn't cause the system property to be // When handled by the command itself it shouldn't cause the system property to be
// set // set
assertEquals(null, System.getProperty("debug")); assertNull(System.getProperty("debug"));
} }
@Test @Test

View File

@ -32,6 +32,7 @@ import org.springframework.test.util.ReflectionTestUtils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
@ -71,7 +72,7 @@ public class PropertiesLauncherTests {
public void testUserSpecifiedMain() throws Exception { public void testUserSpecifiedMain() throws Exception {
PropertiesLauncher launcher = new PropertiesLauncher(); PropertiesLauncher launcher = new PropertiesLauncher();
assertEquals("demo.Application", launcher.getMainClass()); assertEquals("demo.Application", launcher.getMainClass());
assertEquals(null, System.getProperty("loader.main")); assertNull(System.getProperty("loader.main"));
} }
@Test @Test

View File

@ -54,6 +54,7 @@ import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import static java.lang.annotation.RetentionPolicy.RUNTIME; import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
/** /**
* Tests for {@link RelaxedDataBinder}. * Tests for {@link RelaxedDataBinder}.
@ -185,7 +186,7 @@ public class RelaxedDataBinderTests {
BindingResult result = bind(binder, target, "foo: bar\n" + "value: 123\n" BindingResult result = bind(binder, target, "foo: bar\n" + "value: 123\n"
+ "bar: spam"); + "bar: spam");
assertEquals(123, target.getValue()); assertEquals(123, target.getValue());
assertEquals(null, target.getFoo()); assertNull(target.getFoo());
assertEquals(0, result.getErrorCount()); assertEquals(0, result.getErrorCount());
} }

View File

@ -24,6 +24,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
/** /**
* Tests for {@link VcapApplicationListener}. * Tests for {@link VcapApplicationListener}.
@ -52,7 +53,7 @@ public class VcapApplicationListenerTests {
public void testUnparseableApplicationProperties() { public void testUnparseableApplicationProperties() {
EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:"); EnvironmentTestUtils.addEnvironment(this.context, "VCAP_APPLICATION:");
this.initializer.onApplicationEvent(this.event); this.initializer.onApplicationEvent(this.event);
assertEquals(null, this.context.getEnvironment().getProperty("vcap")); assertNull(this.context.getEnvironment().getProperty("vcap"));
} }
@Test @Test
@ -62,7 +63,7 @@ public class VcapApplicationListenerTests {
this.context, this.context,
"VCAP_APPLICATION:{\"application_users\":null,\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\",\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],\"started_at\":\"2013-05-29 02:37:59 +0000\",\"started_at_timestamp\":1369795079,\"host\":\"0.0.0.0\",\"port\":61034,\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\",\"state_timestamp\":1369795079}"); "VCAP_APPLICATION:{\"application_users\":null,\"instance_id\":\"bb7935245adf3e650dfb7c58a06e9ece\",\"instance_index\":0,\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"foo\",\"uris\":[\"foo.cfapps.io\"],\"started_at\":\"2013-05-29 02:37:59 +0000\",\"started_at_timestamp\":1369795079,\"host\":\"0.0.0.0\",\"port\":61034,\"limits\":{\"mem\":128,\"disk\":1024,\"fds\":16384},\"version\":\"3464e092-1c13-462e-a47c-807c30318a50\",\"name\":\"dsyerenv\",\"uris\":[\"dsyerenv.cfapps.io\"],\"users\":[],\"start\":\"2013-05-29 02:37:59 +0000\",\"state_timestamp\":1369795079}");
this.initializer.onApplicationEvent(this.event); this.initializer.onApplicationEvent(this.event);
assertEquals(null, this.context.getEnvironment().getProperty("vcap")); assertNull(this.context.getEnvironment().getProperty("vcap"));
} }
@Test @Test

View File

@ -32,6 +32,7 @@ import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils; import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator; import org.springframework.validation.Validator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -64,7 +65,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
} }
catch (BeanCreationException ex) { catch (BeanCreationException ex) {
BindException bex = (BindException) ex.getRootCause(); BindException bex = (BindException) ex.getRootCause();
assertTrue(1 == bex.getErrorCount()); assertEquals(1, bex.getErrorCount());
} }
} }
@ -78,7 +79,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
} }
catch (BeanCreationException ex) { catch (BeanCreationException ex) {
BindException bex = (BindException) ex.getRootCause(); BindException bex = (BindException) ex.getRootCause();
assertTrue(1 == bex.getErrorCount()); assertEquals(1, bex.getErrorCount());
} }
} }
@ -92,7 +93,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
} }
catch (BeanCreationException ex) { catch (BeanCreationException ex) {
BindException bex = (BindException) ex.getRootCause(); BindException bex = (BindException) ex.getRootCause();
assertTrue(2 == bex.getErrorCount()); assertEquals(2, bex.getErrorCount());
} }
} }

View File

@ -103,7 +103,7 @@ public class YamlMapFactoryBeanTests {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> sub = (Map<String, Object>) object; Map<String, Object> sub = (Map<String, Object>) object;
assertTrue(sub.containsKey("key1.key2")); assertTrue(sub.containsKey("key1.key2"));
assertTrue(sub.get("key1.key2").equals("value")); assertEquals("value", sub.get("key1.key2"));
} }
} }