(t *testing.T)
| 716 | } |
| 717 | |
| 718 | func TestDefaultContainer_CanResolve(t *testing.T) { |
| 719 | var testCases = []struct { |
| 720 | name string |
| 721 | preCondition func(container Container) |
| 722 | instanceName string |
| 723 | |
| 724 | wantResult bool |
| 725 | }{ |
| 726 | { |
| 727 | name: "can resolve instance singleton", |
| 728 | preCondition: func(container Container) { |
| 729 | _ = container.RegisterSingleton("anyInstanceName", &AnyComponent{}) |
| 730 | }, |
| 731 | instanceName: "anyInstanceName", |
| 732 | wantResult: true, |
| 733 | }, |
| 734 | { |
| 735 | name: "can resolve instance definition", |
| 736 | preCondition: func(container Container) { |
| 737 | _ = container.RegisterDefinition(&Definition{ |
| 738 | name: "anyInstanceName", |
| 739 | }) |
| 740 | }, |
| 741 | instanceName: "anyInstanceName", |
| 742 | wantResult: true, |
| 743 | }, |
| 744 | { |
| 745 | name: "cannot resolve instance", |
| 746 | instanceName: "anyInstanceName", |
| 747 | wantResult: false, |
| 748 | }, |
| 749 | } |
| 750 | |
| 751 | for _, tc := range testCases { |
| 752 | t.Run(tc.name, func(t *testing.T) { |
| 753 | // given |
| 754 | container := NewDefaultContainer() |
| 755 | |
| 756 | if tc.preCondition != nil { |
| 757 | tc.preCondition(container) |
| 758 | } |
| 759 | |
| 760 | // when |
| 761 | result := container.CanResolve(tc.instanceName) |
| 762 | |
| 763 | // then |
| 764 | assert.Equal(t, tc.wantResult, result) |
| 765 | }) |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | func TestDefaultContainer_CanResolveType(t *testing.T) { |
| 770 | var testCases = []struct { |
nothing calls this directly
no test coverage detected