Skip to content

Commit

Permalink
Fixing Format and removing author name from new file. Fixes apollocon…
Browse files Browse the repository at this point in the history
  • Loading branch information
ayush0407 committed Mar 21, 2022
1 parent 45f3bbf commit 3aca065
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,53 @@

public class ConfigChangeContentBuilderTest {

private final ConfigChangeContentBuilder configChangeContentBuilder = new ConfigChangeContentBuilder();
private String configString;
private Item createdItem;
private Item updatedItem;
private Item updatedItemFalseCheck;
private Item createdItemFalseCheck;
@Before
public void initConfig() {
private final ConfigChangeContentBuilder configChangeContentBuilder = new ConfigChangeContentBuilder();
private String configString;
private Item createdItem;
private Item updatedItem;
private Item updatedItemFalseCheck;
private Item createdItemFalseCheck;

createdItem = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1);
updatedItem = MockBeanFactory.mockItem(1, 1, "timeout", "1001", 1);
updatedItemFalseCheck = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1);
createdItemFalseCheck = MockBeanFactory.mockItem(1, 1, "", "100", 1);
@Before
public void initConfig() {

configChangeContentBuilder.createItem(createdItem);
configChangeContentBuilder.createItem(createdItemFalseCheck);
configChangeContentBuilder.updateItem(createdItem, updatedItem);
configChangeContentBuilder.updateItem(createdItem, updatedItemFalseCheck);
configChangeContentBuilder.deleteItem(updatedItem);
configChangeContentBuilder.deleteItem(createdItemFalseCheck);
createdItem = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1);
updatedItem = MockBeanFactory.mockItem(1, 1, "timeout", "1001", 1);
updatedItemFalseCheck = MockBeanFactory.mockItem(1, 1, "timeout", "100", 1);
createdItemFalseCheck = MockBeanFactory.mockItem(1, 1, "", "100", 1);
configChangeContentBuilder.createItem(createdItem);
configChangeContentBuilder.createItem(createdItemFalseCheck);
configChangeContentBuilder.updateItem(createdItem, updatedItem);
configChangeContentBuilder.updateItem(createdItem, updatedItemFalseCheck);
configChangeContentBuilder.deleteItem(updatedItem);
configChangeContentBuilder.deleteItem(createdItemFalseCheck);
configString = configChangeContentBuilder.build();
}

configString = configChangeContentBuilder.build();
}

@Test
public void testHasContent() {
assertTrue(configChangeContentBuilder.hasContent());
configChangeContentBuilder.getCreateItems().clear();
assertTrue(configChangeContentBuilder.hasContent());
configChangeContentBuilder.getUpdateItems().clear();
assertTrue(configChangeContentBuilder.hasContent());
}
@Test
public void testHasContent() {
assertTrue(configChangeContentBuilder.hasContent());
configChangeContentBuilder.getCreateItems().clear();
assertTrue(configChangeContentBuilder.hasContent());
configChangeContentBuilder.getUpdateItems().clear();
assertTrue(configChangeContentBuilder.hasContent());
}

@Test
public void testHasContentFalseCheck() {
configChangeContentBuilder.getCreateItems().clear();
configChangeContentBuilder.getUpdateItems().clear();
configChangeContentBuilder.getDeleteItems().clear();
assertFalse(configChangeContentBuilder.hasContent());
}
@Test
public void testHasContentFalseCheck() {
configChangeContentBuilder.getCreateItems().clear();
configChangeContentBuilder.getUpdateItems().clear();
configChangeContentBuilder.getDeleteItems().clear();
assertFalse(configChangeContentBuilder.hasContent());
}

@Test
public void testConvertJsonString() {
ConfigChangeContentBuilder contentBuilder = ConfigChangeContentBuilder
.convertJsonString(configString);

assertNotNull(contentBuilder.getCreateItems());
assertNotNull(contentBuilder.getUpdateItems().get(0).oldItem);
assertNotNull(contentBuilder.getUpdateItems().get(0).newItem);
assertNotNull(contentBuilder.getDeleteItems());
}
@Test
public void testConvertJsonString() {
ConfigChangeContentBuilder contentBuilder = ConfigChangeContentBuilder.convertJsonString(configString);
assertNotNull(contentBuilder.getCreateItems());
assertNotNull(contentBuilder.getUpdateItems().get(0).oldItem);
assertNotNull(contentBuilder.getUpdateItems().get(0).newItem);
assertNotNull(contentBuilder.getDeleteItems());
}

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
/*
* Copyright 2022 Apollo Authors
*
* 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
* 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.
* 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 com.ctrip.framework.apollo.spring.util;
Expand All @@ -32,48 +30,45 @@
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry;

/**
* @author Ayush Jha
*/

@RunWith(MockitoJUnitRunner.class)
public class BeanRegistrationUtilTest {

@InjectMocks
private BeanRegistrationUtil beanRegistrationUtil;
private BeanDefinitionRegistry someRegistry;
private String someBeanName = "someBean";
@InjectMocks
private BeanRegistrationUtil beanRegistrationUtil;
private BeanDefinitionRegistry someRegistry;
private String someBeanName = "someBean";

@Before
public void setUp() {
someRegistry = new SimpleBeanDefinitionRegistry();
}
@Before
public void setUp() {
someRegistry = new SimpleBeanDefinitionRegistry();
}

@Test
public void registerBeanDefinitionIfNotExistsTest() {
someRegistry.registerBeanDefinition(someBeanName, Mockito.mock(BeanDefinition.class));
assertFalse(
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(someRegistry, someBeanName, getClass(), null));
assertFalse(BeanRegistrationUtil.registerBeanDefinitionIfNotExists(someRegistry, someBeanName, getClass()));
@Test
public void registerBeanDefinitionIfNotExistsTest() {
someRegistry.registerBeanDefinition(someBeanName, Mockito.mock(BeanDefinition.class));
assertFalse(BeanRegistrationUtil.registerBeanDefinitionIfNotExists(someRegistry, someBeanName,
getClass(), null));
assertFalse(BeanRegistrationUtil.registerBeanDefinitionIfNotExists(someRegistry, someBeanName,
getClass()));

}
}

@Test
public void registerBeanDefinitionIfNotExistsBeanNotPresentTest() {
someRegistry.registerBeanDefinition("someAnotherBean", Mockito.mock(BeanDefinition.class));
assertTrue(
BeanRegistrationUtil.registerBeanDefinitionIfNotExists(someRegistry, someBeanName, getClass(), null));
@Test
public void registerBeanDefinitionIfNotExistsBeanNotPresentTest() {
someRegistry.registerBeanDefinition("someAnotherBean", Mockito.mock(BeanDefinition.class));
assertTrue(BeanRegistrationUtil.registerBeanDefinitionIfNotExists(someRegistry, someBeanName,
getClass(), null));

}
}

@Test
public void registerBeanDefinitionIfNotExistsWithExtPropTest() {
someRegistry.registerBeanDefinition("someAnotherBean", Mockito.mock(BeanDefinition.class));
Map<String, Object> extraPropertyValues = new ConcurrentHashMap<>();
extraPropertyValues.put(someBeanName, "someProperty");
assertTrue(BeanRegistrationUtil.registerBeanDefinitionIfNotExists(someRegistry, someBeanName, getClass(),
extraPropertyValues));
@Test
public void registerBeanDefinitionIfNotExistsWithExtPropTest() {
someRegistry.registerBeanDefinition("someAnotherBean", Mockito.mock(BeanDefinition.class));
Map<String, Object> extraPropertyValues = new ConcurrentHashMap<>();
extraPropertyValues.put(someBeanName, "someProperty");
assertTrue(BeanRegistrationUtil.registerBeanDefinitionIfNotExists(someRegistry, someBeanName,
getClass(), extraPropertyValues));

}
}

}

0 comments on commit 3aca065

Please sign in to comment.