forked from apache/netbeans
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request apache#1979 from hectorespert/test_notification_mo…
…dule Add tests in notifications module
- Loading branch information
Showing
12 changed files
with
633 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...ifications/test/unit/src/org/netbeans/modules/notifications/NotificationSettingsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.netbeans.modules.notifications; | ||
|
||
import org.junit.Test; | ||
import org.netbeans.junit.NbTestCase; | ||
|
||
/** | ||
* | ||
* @author Hector Espert | ||
*/ | ||
public class NotificationSettingsTest extends NbTestCase { | ||
|
||
public NotificationSettingsTest(String name) { | ||
super(name); | ||
} | ||
|
||
@Test | ||
public void testIsSearchVisible() { | ||
NotificationSettings.setSearchVisible(false); | ||
assertFalse(NotificationSettings.isSearchVisible()); | ||
|
||
NotificationSettings.setSearchVisible(true); | ||
assertTrue(NotificationSettings.isSearchVisible()); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...notifications/test/unit/src/org/netbeans/modules/notifications/StatusLineElementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.netbeans.modules.notifications; | ||
|
||
import java.awt.Component; | ||
import org.junit.Test; | ||
import org.netbeans.junit.NbTestCase; | ||
import org.openide.awt.StatusLineElementProvider; | ||
import org.openide.util.Lookup; | ||
|
||
/** | ||
* | ||
* @author Hector Espert | ||
*/ | ||
public class StatusLineElementTest extends NbTestCase { | ||
|
||
public StatusLineElementTest(String name) { | ||
super(name); | ||
} | ||
|
||
@Test | ||
public void testGetStatusLineElement() { | ||
StatusLineElementProvider statusLineElementProvider = Lookup.getDefault().lookup(StatusLineElementProvider.class); | ||
assertNotNull(statusLineElementProvider); | ||
assertEquals(StatusLineElement.class, statusLineElementProvider.getClass()); | ||
|
||
Component component = statusLineElementProvider.getStatusLineElement(); | ||
assertNotNull(component); | ||
assertEquals("Expected that org.netbeans.modules.notifications.FlashingIcon is the default implementation", FlashingIcon.class, component.getClass()); | ||
} | ||
|
||
} |
124 changes: 124 additions & 0 deletions
124
...cations/test/unit/src/org/netbeans/modules/notifications/filter/FilterRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.netbeans.modules.notifications.filter; | ||
|
||
import java.util.Iterator; | ||
import static org.junit.Assert.*; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* | ||
* @author Hector Espert | ||
*/ | ||
public class FilterRepositoryTest { | ||
|
||
private FilterRepository filterRepository; | ||
|
||
@Before | ||
public void setUp() { | ||
filterRepository = new FilterRepository(); | ||
} | ||
|
||
@Test | ||
public void testAssign() { | ||
FilterRepository instance = new FilterRepository(); | ||
instance.setActive(NotificationFilter.EMPTY); | ||
filterRepository.assign(instance); | ||
assertEquals(instance.getAllFilters(), filterRepository.getAllFilters()); | ||
assertEquals(NotificationFilter.EMPTY, filterRepository.getActive()); | ||
} | ||
|
||
@Test | ||
public void testClone() { | ||
FilterRepository result = (FilterRepository) filterRepository.clone(); | ||
assertEquals(filterRepository.getAllFilters(), result.getAllFilters()); | ||
assertEquals(filterRepository.getActive(), result.getActive()); | ||
} | ||
|
||
@Test | ||
public void testGetAllFilters() { | ||
assertNotNull(filterRepository.getAllFilters()); | ||
} | ||
|
||
@Test | ||
public void testAddAndRemoveFilter() { | ||
filterRepository.add(NotificationFilter.EMPTY); | ||
assertTrue(filterRepository.getFilters().contains(NotificationFilter.EMPTY)); | ||
filterRepository.remove(NotificationFilter.EMPTY); | ||
assertFalse(filterRepository.getFilters().contains(NotificationFilter.EMPTY)); | ||
} | ||
|
||
@Test | ||
public void testIterator() { | ||
assertTrue(filterRepository.iterator() instanceof Iterator); | ||
} | ||
|
||
@Test | ||
public void testSize() { | ||
assertEquals(0, filterRepository.size()); | ||
filterRepository.add(NotificationFilter.EMPTY); | ||
assertEquals(1, filterRepository.size()); | ||
} | ||
|
||
@Test | ||
public void testGetFilterByName() { | ||
NotificationFilter filter = NotificationFilter.EMPTY; | ||
filter.setName("EMPTY"); | ||
filterRepository.add(filter); | ||
assertEquals(filter, filterRepository.getFilterByName("EMPTY")); | ||
} | ||
|
||
@Test | ||
public void testGetActive() { | ||
NotificationFilter filter = NotificationFilter.EMPTY; | ||
filterRepository.setActive(filter); | ||
assertEquals(filter, filterRepository.getActive()); | ||
} | ||
|
||
@Test | ||
public void testSaveAndLoad() throws Exception { | ||
NotificationFilter filter = NotificationFilter.EMPTY; | ||
filter.setName("EMPTY"); | ||
filterRepository.add(filter); | ||
assertEquals(1, filterRepository.size()); | ||
|
||
filterRepository.save(); | ||
|
||
filterRepository.clear(); | ||
assertEquals(0, filterRepository.size()); | ||
|
||
filterRepository.load(); | ||
assertEquals(1, filterRepository.size()); | ||
assertEquals("EMPTY", filterRepository.getActive().getName()); | ||
} | ||
|
||
@Test | ||
public void testCreateNewFilter() { | ||
NotificationFilter result = filterRepository.createNewFilter(); | ||
assertNotNull(result); | ||
assertEquals("New Filter", result.getName()); | ||
} | ||
|
||
@Test | ||
public void testGetFilters() { | ||
assertNotNull(filterRepository.getFilters()); | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
...tions/test/unit/src/org/netbeans/modules/notifications/filter/NotificationFilterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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.netbeans.modules.notifications.filter; | ||
|
||
import java.util.prefs.Preferences; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import static org.junit.Assert.*; | ||
import org.netbeans.modules.notifications.NotificationImpl; | ||
import org.openide.awt.NotificationDisplayer; | ||
|
||
/** | ||
* | ||
* @author Hector Espert | ||
*/ | ||
public class NotificationFilterTest { | ||
|
||
private NotificationFilter notificationFilter; | ||
|
||
@Before | ||
public void setUp() { | ||
notificationFilter = new NotificationFilter("testfilter"); | ||
} | ||
|
||
|
||
@Test | ||
public void testIsEnabled() { | ||
NotificationImpl errorNotification = new NotificationImpl(null, null, null, NotificationDisplayer.Category.ERROR, null); | ||
assertTrue(notificationFilter.isEnabled(errorNotification)); | ||
|
||
CategoryFilter categoryFilter = new CategoryFilter(); | ||
categoryFilter.setEnabled("default_category_error", false); | ||
notificationFilter.setCategoryFilter(categoryFilter); | ||
|
||
assertFalse(notificationFilter.isEnabled(errorNotification)); | ||
} | ||
|
||
@Test | ||
public void testClone() { | ||
CategoryFilter categoryFilter = new CategoryFilter(); | ||
categoryFilter.setEnabled("default_category_error", false); | ||
notificationFilter.setCategoryFilter(categoryFilter); | ||
|
||
NotificationFilter cloned = (NotificationFilter) notificationFilter.clone(); | ||
assertNotNull(cloned); | ||
|
||
assertEquals(notificationFilter.getName(), cloned.getName()); | ||
assertEquals(notificationFilter.getCategoryFilter().isEnabled("default_category_error"), cloned.getCategoryFilter().isEnabled("default_category_error")); | ||
} | ||
|
||
@Test | ||
public void testToString() { | ||
assertEquals("testfilter", notificationFilter.toString()); | ||
} | ||
|
||
@Test | ||
public void testLoad() throws Exception { | ||
Preferences preferences = new TestPreferences(); | ||
notificationFilter.load(preferences, "test"); | ||
|
||
assertEquals("test_name Filter", notificationFilter.getName()); | ||
assertTrue(notificationFilter.getCategoryFilter().isEnabled("test_category_error")); | ||
|
||
} | ||
|
||
@Test | ||
public void testSave() throws Exception { | ||
Preferences preferences = new TestPreferences(); | ||
notificationFilter.save(preferences, "test"); | ||
} | ||
|
||
} |
Oops, something went wrong.